If you want to check whether a configuration file is correct, an error is reported after – C is specified, as follows:
[root@op-2:~# 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
Sometimes the file is correct, but it will also report an error
The practical problem is that the object of syntax detection has problems
To detect whether there are errors in the existing modified nginx configuration, we should not only detect the. Conf file, but always detect the main file/etc/nginx/nginx.conf at any time. Only in this way can we load the. Conf file in the corresponding module smoothly
This ensures the correctness of the context before and after the configuration, which is the real detection
So the correct command to detect whether the syntax of the modified nginx is wrong should be: nginx - t - C/etc/nginx/nginx. Conf
, if there is an exception in the configuration file, it will be reported directly, otherwise it will be
[ root@op-2 :~# 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
[ root@op-2 :~# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful