With Apache, if I want to slightly modify a "Rewrite rule" for a website on my server, I can just edit a few lines in /var/www/website5/.htaccess
, save and it will be immediately active.
Benefit: it's not required to service apache2 restart
, thus it won't interrupt ongoing connections on other websites that are on the same server (let's imagine someone is currently downloading a big 1 GB, I would prefer not to interrupt this!).
Question: I'm now testing nginx, I read that there is no "natural" equivalent of .htaccess (of course, there are add-ons that allow this, but here I'm really focusing on understanding the original philosophy of nginx, that does not have this feature).
How to slightly modify the nginx
configuration (e.g. URL rewrite rules) of a website, without requiring the whole server (hosting many websites) to restart?
PS:
if there exists a "graceful reload" feature that waits for requests to be terminated before restarting nginx, does this mean that if a client just begun the download of a 2GB file that will last 2 hours, nginx will wait 2 hours (for the request to be completed) before reloading the new configuration?
Then it would be very difficult to modify the configuration if we have to potentially wait minutes/hours to test that config modifications are done.if the latter problem doesn't exist, how does it work? (is there a documentation source about this specific point?)
Restarting the nginx service may be avoided by using 'reload' instead. You can use the command
service nginx reload
. This will reload nginx without downtime. Be sure to first check your nginx syntax:service nginx configtest
.This could be done in one command:
The
&&
wil only continue of the first command has giving the 0 exit code, indicating there were no issues in the syntax of the configuration.While doing a reload the Nginx proceses will gracefully shutdown. More information on this can be found in Nginx' documentation.
Example:
If you have 4 Nginx worker processes and one has a long lasting download, you will have 5 worker processes after a reload: 4 fresh workers and one handling your download until it has been finished, marked as shutdown.