nginx检查配置文件语法是否正常,需要检查主配置文件
https://www.shuizhongyueming.com/2014/11/04/the-possible-reason-for-the-nginx-error-emerg-server-directive-is-not-allowed-here/? 原文鏈接,懶得改了,就抄的,不要噴我,并不是為了盈利,純屬個人記錄,方便自己以后操作
?
Nginx 錯誤[emerg] "server" directive is not allowed here的可能情況
Nginx Nginx 錯誤[emerg] "server" directive is not allowed here的可能情況-
服務器環境:
ubuntu 14.04, nginx/1.4.6 -
執行命令:
sudo nginx -t -c /etc/nginx/conf.d/default.conf -
命令目的:查看新修改的nginx是否有錯誤,避免上線導致服務器出錯
執行結果:
nginx: \[emerg\] "server" directive is not allowed here in /etc/nginx/conf.d/default.conf:1 nginx: configuration file /etc/nginx/conf.d/default.conf test failed default.conf里面的內容:
server {listen 80; server_name localhostmanager.com www.shuizhongyueming.com; root /var/www/www.shuizhongyueming.com; location / { index index.html index.php; } # 媒體資源文件 # TODO: 用一個static.hostmanager.com 之類的域名放置 location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } # 前端代碼 # TODO: 用一個fe.hostmanager.com之類的域名放置 location ~ .*.(js|css)$ { expires 1h; } } 一開始以為是語法錯誤,可是復制了官方文檔里面的一個簡單PHP站點配置之后,還是報同樣的錯誤,所以基本算排除了語法錯誤
上網Google的結果,大多說的是server的配置應該放在http里面
可是我的default.conf?是在/etc/nginx/nginx.conf?里面,在http模塊下include的,不應該有任何的錯誤才對
最后自己根據網上這些答案猜測,是我進行語法檢測的對象有問題。
要檢測現有的修改過的Nginx配置是否有錯誤,不是單單檢測那個修改過的擴展的.conf文件。而是不管任何時候,始終都是去檢測主文件/etc/nginx/nginx.conf,只有這樣,才能順利的在對應的模塊加載擴展的.conf文件。
這樣一來保證了配置的前后語境的正確性,二來,這樣才是真正的檢測(完全和實際運行情況相符)
所以正確的檢測修改的Nginx的語法是否錯誤的命令應該是:sudo nginx -t -c /etc/nginx/nginx.conf,然后一個欣喜的結果就會是:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful 希望這個小的發現能幫助到大家。
?
?
?
https://www.shuizhongyueming.com/2014/11/04/the-possible-reason-for-the-nginx-error-emerg-server-directive-is-not-allowed-here/
轉載于:https://www.cnblogs.com/buxuxiao/p/11416661.html
總結
以上是生活随笔為你收集整理的nginx检查配置文件语法是否正常,需要检查主配置文件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 003_如何学好英语?
- 下一篇: 微信小程序下拉刷新真机无法弹回