联系QQ 284710375
首页 > 技术分享 > LNMP|WAMP
收藏

验证nginx配置文件是否正确,nginx -t和nginx -t -c的使用2018-01-15 16:23:18

大潇博客 原创文章,转载请标明出处
验证nginx配置文件是否正确:
如果nginx已经成为本地service,不管在什么目录下,直接用nginx -t即可
未成为service,进入nginx安装目录,如nginx安装在/usr/local/nginx/下,则可用/usr/local/nginx/sbin/nginx -t
如果提示:
nginx.conf syntax is ok
nginx.conf test is successful
说明配置文件正确!


如果想验证单个域名配置文件,则可用nginx -t -c,具体用法:

例如在/usr/local/nginx/conf/vhost/文件夹下存着nginx域名配置文件www.test.com.conf,验证这个配置文件是否正确,则可用:nginx -t -c /etc/nginx/conf/vhost/www.test.com.conf进行验证
如果提示:
nginx.conf syntax is ok
nginx.conf test is successful
说明配置文件正确!

在使用nginx -t -c时,可能出现如下错误
1、"server" directive is not allowed here
错误原因:配置文件的server段没有放到http{}中
解决方法:打开要验证的配置文件,使用http{}把所有server段包起来

2、no "events" section in configuration
错误原因:没有加入events{}
解决方法:在验证的配置最上方加入如下配置:
events {
    worker_connections  1024;  ## Default: 1024
}
不加没有啥影响,不加nginx就用默认的1024

打赏

阅读排行

大家都在搜

博客维护不易,感谢你的肯定
扫码打赏,建议金额1-10元
  • 15601023311