Contents
- What should you do before changing a live website?
- Why use a reload instead of a restart?
- How do you find the configuration NGINX actually uses?
- How do you back up the right files?
- How do you test and apply the edit?
- How do you verify that visitors get the intended result?
- How do you recover from a failed reload or a bad change?
- Which mistakes should you avoid next time?
- How does CH-J Tools help with NGINX configuration?
- Frequently asked questions
What should you do before changing a live website?
You need to replace a certificate, change a reverse proxy destination or correct a redirect while visitors are using the website. Saving the file does not apply the change to running NGINX workers. The safe routine is to identify the active configuration, preserve the working files, test the edit, request a reload and verify the actual website. Each step answers a different question; a successful syntax test alone is not proof that users receive the right page.
The commands below target a package installation on Debian or Ubuntu with systemd and the nginx service. Run them on the Linux server, including when you administer it over SSH from Windows. Replace server.example and the example configuration filename with your own values. On RHEL installations the service is commonly also nginx, but virtual host files are usually under /etc/nginx/conf.d rather than sites-available. Inspect the local configuration before adapting the paths.
Why use a reload instead of a restart?
During a reload, the master process tries to apply the configuration and, if successful, starts new workers. Old workers stop accepting new connections and finish their existing work before exiting. If the master cannot apply the configuration, it continues using the previous one. This protects an already running service from many configuration mistakes, but does not make a logically wrong redirect or proxy destination correct.
A restart stops and starts the service. Its connection handling depends on the service unit and timeouts, and there is a period when the service is not listening. If startup fails, there are no working old workers to keep serving visitors. Use reload for routine configuration edits rather than treating restart as the default way to save changes.
- A reload applies configuration changes; it does not replace the running executable after a package upgrade.
- A reload does not repair an unavailable application behind the reverse proxy.
- Existing long connections can keep old workers alive, so a graceful transition need not finish immediately.
How do you find the configuration NGINX actually uses?
Check service status and the unit definition first. A custom installation can select another executable, configuration file or prefix. If the unit uses -c or -p, use the same executable and relevant options for your tests. Do not test the package default while reloading a different instance. Containers and installations without systemd need their own service management procedure.
sudo systemctl status nginx --no-pager
sudo systemctl cat nginx
sudo nginx -t
sudo nginx -T | lessThe -T option tests and prints the configuration files, including included files. It shows what is on disk now, not a dump of the configuration held by existing workers. Find the server_name and listen directives for your website and note which file contains them. On Debian and Ubuntu, inspect the enabled entry before editing its target:
ls -l /etc/nginx/sites-enabled/server.example.conf
readlink -f /etc/nginx/sites-enabled/server.example.confConfiguration output can contain credentials, tokens or internal addresses. Review and redact it before sharing it in tickets or chat; do not publish the full nginx -T output.
How do you back up the right files?
Start with a passing test of the unchanged configuration. If it already fails, diagnose that condition before adding another change. On Debian and Ubuntu, an entry in sites-enabled is usually a symbolic link to a regular file in sites-available. Edit and back up that target file. Verify the paths rather than assuming that every installation follows this convention.
Keep the backup outside every include pattern. A copy named server.example.conf.backup still matches sites-enabled/*, even though it does not end in .conf. The following example stores the copy under /root and preserves file attributes. Record the resulting backup path; the shell variable is available only in the current shell.
nginx_backup_path="/root/server.example.conf.$(date +%Y%m%d-%H%M%S)"
sudo cp -a /etc/nginx/sites-available/server.example.conf "$nginx_backup_path"
sudo ls -l "$nginx_backup_path"Proceed only after the copy succeeds. If the change spans several files, preserve each one and record any new files or links you create. Restoring a single virtual host will not undo an edit in a shared include. For certificate work, keep the previous certificate and matching key available securely as well.
How do you test and apply the edit?
- Edit the confirmed target file with an editor that can save it with the required privileges. Make one understandable change at a time.
- Review the difference against the backup. Confirm that unrelated server blocks, access rules and certificate paths have not changed.
- Run nginx -t as root through sudo. Read warnings as well as the final success or failure message.
- If the test fails, correct the reported file and line, then test again. Leave the running service alone while fixing the files.
- After a successful test, request a reload and immediately inspect status and recent logs. Then perform the website checks in the next section.
sudoedit /etc/nginx/sites-available/server.example.conf
sudo nginx -t && sudo systemctl reload nginx
sudo systemctl status nginx --no-pager
sudo journalctl -u nginx -n 50 --no-pagerThe && operator prevents the reload command from running when the test exits unsuccessfully. It does not prevent another administrator or deployment job from changing a file between the test and reload. Coordinate the edit so that the files you test remain the files you apply.
For a standard /etc/nginx/nginx.conf installation, successful test output can look like this. This is example output, not a command to run:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successfulA test checks syntax and attempts to open referenced files, including certificates. It does not prove that an upstream application responds or that a redirect is correct. An active service can also still be using the previous configuration after a rejected reload, so service status is only one part of verification.
How do you verify that visitors get the intended result?
Test both the public route and, where appropriate, the changed server directly. A public request can be answered by a CDN, cache or another node. In the second command below, replace the documentation address 203.0.113.10 with the server address. curl --resolve keeps the URL hostname for HTTP and TLS while choosing the destination address; use it from a machine that can reach the server.
curl -I https://server.example/
curl --resolve server.example:443:203.0.113.10 -I https://server.example/
curl --resolve server.example:443:203.0.113.10 -sS -o /dev/null -w "%{http_code}\n" https://server.example/- Check the expected status and Location header. A deliberate redirect can be correct even when the response is not 200.
- Check a normal page and the specific path you changed. The final command makes a GET request because some applications treat HEAD differently.
- Open the website in a browser and exercise the affected function, including authentication or a WebSocket connection when relevant.
- Inspect the configured access and error logs for new failures, and repeat the check for each changed node behind a load balancer.
Keep TLS verification enabled. A certificate failure is part of the result you need to investigate. Compare the response with a baseline taken before the edit so that an unrelated pre-existing error does not get mistaken for a new regression.
How do you recover from a failed reload or a bad change?
First establish whether NGINX is still serving the old configuration or whether the service has stopped. Read the test error, journal and configured error log. The path below is common on Debian and Ubuntu; use the path from your configuration if it differs. A missing certificate or invalid directive can fail testing; an occupied new listening port can prevent applying a reload.
sudo nginx -t
sudo journalctl -u nginx -n 50 --no-pager
sudo tail -n 50 /var/log/nginx/error.log
sudo ss -ltnpFor the single-file edit above, confirm the recorded backup path and inspect the difference before restoring it. If you opened another shell, set nginx_backup_path to the actual saved path first. diff returns 1 when files differ; that normally means there are changes to review, not that the comparison failed.
sudo ls -l "$nginx_backup_path"
sudo diff -u "$nginx_backup_path" /etc/nginx/sites-available/server.example.confRestoring the backup overwrites the current file. Confirm that it is the intended known working copy and preserve any later edits you need before proceeding. Coordinate with other administrators so you do not erase their work.
Reload only if the service is running. If it is stopped, restore and test the configuration first, then use sudo systemctl start nginx and repeat the website checks. If you changed several files, restore the whole recorded change, including any added includes. A rollback is complete only after the service and affected website behavior have been verified.
sudo test -f "$nginx_backup_path" &&
sudo cp -a "$nginx_backup_path" /etc/nginx/sites-available/server.example.conf &&
sudo nginx -t && sudo systemctl reload nginxWhich mistakes should you avoid next time?
- Do not restart repeatedly after a failed test. Keep the working processes available while repairing the configuration on disk.
- Do not leave editor backups or duplicate virtual hosts in included directories. Read the actual include patterns before deciding where a copy is safe.
- Do not replace a sites-enabled symlink with a regular file. Edit the confirmed target so later maintenance does not involve two diverging copies.
- Do not ignore conflicting server name warnings. A successful test can still report a warning that explains why requests reach an unexpected server block.
- Do not kill draining workers merely because they remain visible after reload. Long-lived connections such as WebSockets may still depend on them.
- Do not combine a routine configuration edit with an unplanned package upgrade. Package scripts may restart the service and require a separate maintenance plan.
Rehearse larger routing, certificate and access-control changes on a test server. Keep configuration history, the reason for each change and a short verification checklist. Allow draining workers time to exit and watch memory use during the transition. Several rapid reloads can leave multiple generations of workers alive when connections are long lived.
How does CH-J Tools help with NGINX configuration?
NGINX Manager edits configuration files in the managed NGINX directories on Linux servers, with a limit of 512 KiB per file. Its save and reload behavior follows these checks:
- When saving, the application creates a backup with a .chj-backup- suffix, runs nginx -t and keeps the change only after a successful test.
- A reload requires your explicit confirmation and runs the configuration test again before it starts.
- An enabled symbolic link is not replaced; edit the matching file in sites-available.
Frequently asked questions
Does nginx -t reload the configuration?
No. It tests the files on disk without applying them to running workers. nginx -T also prints those files. A separate reload is needed after a successful test.
Can I reload NGINX without systemctl?
Yes. nginx -s reload sends a reload signal to the master. Use the correct executable, privileges and configuration or prefix options for that instance. Prefer the service manager for a systemd-managed installation.
Why does my website still show the old configuration?
The master may have rejected the reload, you may have edited an unused file, or your request may reach another node or cache. Check logs, includes and the destination server before repeating the reload.
Does replacing a TLS certificate require an NGINX restart?
For a normal certificate file replacement, test the configuration and reload so new workers use the replacement. Check the certificate and key paths and verify a fresh TLS connection afterwards.
Is a graceful reload guaranteed to cause zero downtime?
It is designed to preserve service during ordinary configuration changes, but cannot guarantee application health or correct routing. Long-lived connections and protocol-specific behavior also matter. Verify the protocols and user flows your website actually uses.