Use sudo nginx -t to test config, then sudo systemctl reload nginx to apply changes without downtime; Nginx spawns new workers while old ones finish ongoing requests.
To restart Nginx without causing downtime, you don't need to fully stop and start the service. Instead, use the reload method, which gracefully restarts Nginx by applying configuration changes while keeping existing connections alive.
Use Nginx Reload Command
The safest way to "restart" Nginx without interrupting active connections is to send a reload signal. This tells the master process to reload the configuration and spawn new worker processes, while allowing old workers to finish handling ongoing requests.
- sudo nginx -s reload – sends the reload signal using the binary directly
- sudo systemctl reload nginx – uses systemd (common on Ubuntu, Debian, CentOS)
- sudo service nginx reload – older init systems
Verify Configuration Before Reloading
Before reloading, always test your configuration to avoid syntax errors that could disrupt service:
- sudo nginx -t – tests the config files for syntax and validity
- If the test passes, proceed with reload. If not, fix the reported issues first.
How It Works Without Downtime
During a reload:
- The master process reads the new configuration.
- New worker processes are started with the updated settings.
- Old worker processes continue serving existing connections until they complete. li>
- Once all old requests are handled, old workers shut down cleanly.
This process ensures no dropped connections or service interruptions under normal conditions.
Basically, just test config and use reload — it's designed exactly for zero-downtime updates.
The above is the detailed content of How to restart Nginx without downtime. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

ArtGPT
AI image generator for creative art from text prompts.

Stock Market GPT
AI powered investment research for smarter decisions

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Installapache2-utilsorhttpd-toolstousehtpasswd.2.Createasecurepasswordfilewithsudohtpasswd-c/etc/nginx/.htpasswdusername.3.ConfigureNginxbyaddingauth_basicandauth_basic_user_filedirectivesinthedesiredlocationblock.4.Testconfigurationwithsudonginx-tan

NginxSSL termination means that Nginx decrypts traffic after receiving a client HTTPS request and forwards the decrypted HTTP request to the backend server. 1.Nginx serves as a reverse proxy, receives encryption requests on port 443, and uses SSL certificates and private keys to decrypt data. 2. After decryption, Nginx forwards the request to the backend service via HTTP or internal HTTPS. 3. The backend response is returned by Nginx and re-encrypted if necessary. Advantages include: improving performance, offloading CPU-consuming decryption tasks from the backend to efficiently process connections; centrally managing certificates to simplify update processes; enhancing flexibility, supporting enabling HTTP/2, compression, caching and load balancing on decrypted traffic; simplifying backend configuration

proxy_passforwardsclientrequeststobackendservers,enablingNginxtoactasareverseproxy;ithandlesdynamiccontentbydelegatingtoapplicationserverslikeNode.jsorPython,supportsloadbalancingviaupstreamblocks,enhancessecurityandperformancewithheadermanipulationa

Nginx cache clearing needs to be operated according to the configuration method, because there is no built-in clear command. 1. For disk proxy cache, find the path specified by proxy_cache_path (such as /var/cache/nginx), delete the file below and restart Nginx. 2. If the cache clearing function is enabled, you can configure location~/purge to clear a specified URL, such as curl-XPURGE to clear a single page. 3. When using FastCGI cache, clear the directory file corresponding to fastcgi_cache_path and restart the service. 4. After clearing, you can use curl-I to check the response header X-Cache: MISS to confirm that the cache has expired. The core is matching configuration

Nginx variables start with $ and are used to dynamically store and reuse values. They can be defined through set directives, such as set$env "production"; they support built-in variables such as $request_uri, $host, etc. for logging and conditional judgment; variable-based redirection and URL rewriting can be achieved in combination with if and rewrite; but variables are only valid in server and location, and some instructions do not support variables.

ThemainNginxconfigurationfileisusuallyat/etc/nginx/nginx.conf;commonalternativesinclude/usr/local/nginx/conf/nginx.confand/opt/nginx/conf/nginx.conf,withsite-specificfilesin/etc/nginx/sites-available/and/etc/nginx/sites-enabled/,or/etc/nginx/conf.d/o

TodeployaReactapponNginx,servestaticfilesandconfigureroutingfallbacktoindex.html.First,buildtheappusingnpmrunbuild,thentransferthebuildfilestotheserverdirectory(e.g.,/var/www/my-react-app).Next,createanNginxserverblockpointingtothisdirectory,usingtry

Answer: Nginx health check depends on the version. The open source version supports passive checking, which is implemented through max_fails and fail_timeout, such as blocking for 30 seconds after three failures; NginxPlus supports active checking, using the health_check instruction to send requests every 5 seconds, verify status codes and response content, and can monitor the backend status through the API.
