How to make the changes in the nginx configuration file take effect?
After modifying the nginx configuration file, you can make it take effect by following these steps:
- Check for syntax errors in the configuration file: use the command “nginx -t” to check if your modifications have caused any syntax errors. Any errors will be displayed with specific information, including the line number and file path where the error occurred. If there are no errors, the message “syntax is ok” will be displayed.
- Reload the nginx configuration: Use the command “nginx -s reload” to reload the nginx configuration file. This command sends a signal to the nginx main process to notify it to reload the configuration file and apply any changes. If there are syntax errors in the configuration file, nginx will not reload and will keep the previous configuration.
- To restart the nginx service, use the command “service nginx restart” or “/etc/init.d/nginx restart.” This will first stop the current running nginx process, then start a new nginx process that will read and apply the modified configuration file.
Please note that reloading the configuration file will not interrupt ongoing requests, whereas restarting the Nginx service will interrupt ongoing requests. Therefore, if you have made minor changes and want to minimize interruptions to ongoing requests, it is recommended to use the method of reloading the configuration file. If you have made significant changes or encountered issues, consider restarting the Nginx service.