How to achieve nginx smooth restart and upgrade?

10-16-2023

If you change the configuration file (nginx.conf) of nginx, you can also restart nginx by sending a system signal to the main process of nginx. However, before restarting, make sure that the syntax of nginx configuration file (nginx.conf) is correct, otherwise nginx will not load a new configuration file. You can judge whether the nginx configuration file is correct by the following command:

/usr/local/webserver/nginx/sbin/nginx-t-c/usr/local/webserver/nginx/conf/nginx.conf If the configuration file is incorrect, the screen will prompt which line of the configuration file is wrong:

[emerg]:unknowndirective"abc"inlusrllocauwebserverlnginxjconflnginx.conf:55configurationfile/usr/local/webserver/nginx/conf/nginx·conf test failed

If the configuration file is correct, the screen will prompt the following two lines of information:

the configuration file/usr/loca/webserver/nginx/conf/nginx.conf syntax is okconfiguration file/usr/local/webserver/nginx/conf/nginx.conf test is successful

At this point, you can restart nginx smoothly.

The copy code code is as follows:

/usr/local/www/nginx/sbin/nginx -xs reloadx

Or:

The copy code code is as follows:

killx -hup `cat /usr/local/www/nginx/logs/nginx.pidx`

Here are some supplements:

Restart kill-hup`cat/usr/local/www/nginx/logs/nginx.pid` smoothly.

Smooth upgrade nginx

cd /yujialinwget http://nginx.org/download/nginx-1.0.6.tar.gztar zxvf nginx-1.0.6.tar.gzcd nginx-1.0.6

/usr/local/www/nginx/sbin/nginx -vnginx: nginx version: nginx/1.0.4nginx: built by gcc 4.1.2 20080704 (red hat 4.1.2-50) Nginx: configure arguments:-prefix =/usr/local/www/nginx-with-pcre =/yujialin/pcre-8.12-with-http _ stub _ status _ module-with-http _ gzip _ static _ module This step is to get the compilation parameters.

./configure-prefix =/usr/local/www/nginx-with-pcre =/yujialin/pcre-8.12-with-http _ stub _ status _ module-with-http _ gzip _ static _ module compiled with the above paragraph.

Then make, never make install.

After make, there will be a nginx in the objs directory, and this is the new version of the program. MV/USR/Local/www/Nginx/USR/Local/www/Nginx/sbin/Nginx-20110906cpobjs/Nginx/USR/Local/www/Nginx/Sbinx.

/usr/local/www/nginx/sbin/nginx -tnginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx/conf/nginx.conf test is successfu

Make upgrade to perform the upgrade.

After execution,/usr/local/nginx/sbin/nginx-vnginx: nginx version: nginx/1.0.6 nginx: built by gcc 4.1.2 20080704 (Red Hat 4.1.2-50). nginx: configure arguments: --prefix=/usr/local/www/nginx --with-pcre=/yujialin/pcre-8.12 --with-http_stub_status_module --with-http_gzip_static_module

Copyright Description:No reproduction without permission。

Knowledge sharing community for developers。

Let more developers benefit from it。

Help developers share knowledge through the Internet。

Follow us