问题出现的原因是直接使用了default.conf文件
[root@test nginx]# nginx -t -c /etc/nginx/conf.d/default.conf
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
正确的检测修改的Nginx的语法是否错误的命令应该是:
[root@test nginx]# nginx -t -c /etc/nginx/nginx.conf
,如果配置文件有异常,会直接报出错误
[root@test nginx]# 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