原文鏈接 https://bysocket.com/nginx-unexpected-end-of-file-expecting-in-key-file/
一、Nginx unexpected end of file 問題
通過 letsencrypt 申請證書后,默認服務(wù)器安裝了 Nginx 1.8 發(fā)現(xiàn),在默認的 /etc/nginx/sites-enabled/default 內(nèi)容配置 SSL 的 site.com.key 后。重啟 Nginx 出現(xiàn)一下錯誤:
nginx: [emerg] unexpected end of file, expecting ";" or "}" in /etc/nginx/sites-enabled/site.com.key:27
二、定位和解決
上述通過日志發(fā)現(xiàn)了這個問題,日常谷歌下,發(fā)現(xiàn)都不是在這個問題。普遍的是 conf 文件,少了 ";" or "}" 結(jié)尾。我這個提示最關(guān)鍵的是說 SSL key 文件里面存在這個問題,其實 SSL 生成文件沒錯。
后來發(fā)現(xiàn),原來是默認 nginx 的問題。
解決方法:
將 /etc/nginx/sites-enabled/default 里面配置 server 遷移到主配置文件 /etc/nginx/nginx.conf
原因:
默認 nginx 有如下配置:
- 主配置文件 /etc/nginx/nginx.conf
- include 了默認 server 內(nèi)容文件 /etc/nginx/sites-enabled/default
但默認 server 相關(guān)文件內(nèi)寫入 SSL 相關(guān)信息會上述的錯誤
出處:公號「程序員泥瓦匠」
博客: https://bysocket.com/內(nèi)容涵蓋 Java 后端技術(shù)、Spring Boot、Spring Cloud、微服務(wù)架構(gòu)、運維開發(fā)、系統(tǒng)監(jiān)控等相關(guān)的研究與知識分享。