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
Similar Posts:
- [Solved] Nginx Log Error: open() “/opt/Nginx/nginx/nginx.pid” failed (2: No such file or directory)
- [Solved] Nginx: [error] open() "/usr/local/Nginx/logs/Nginx.pid
- [Solved] Nginx can’t listen to the problem of virtual VIP: 99: cannot assign requested address
- How to Solve Nginx error: 403 Forbidden
- nginx.service – A high performance web server and a reverse proxy server
- [Solved] Nginx Restart Error: nginx: [error] open() “/usr/local/nginx/logs/nginx.pid” failed (2: No such file or directory)
- Nginx Failed to Starup Error: [emerg] mkdir() “/var/tmp/nginx/client” failed (2: No such file or directory)
- Nginx+PHP FastCGI sent in stderr: “Primary script unknown” while reading response head…
- [Solved] Nginx restart error: nginx: [error] open() “/run/nginx.pid” failed (2: No such file or directory)
- Nginx Error: Nginx 403 error:directory index of “xxx“ is forbidden