Nginx is a popular web server and content management system. It’s free and open source, and it can be used on a wide range of platforms. One of the most important things you can do when setting up Nginx is to make sure your configuration file is correct. This article will show you how to test your Nginx configuration file for correctness.
- Open a new terminal window and type nginx -t to start Nginx.
- In the terminal window, type the following command to create a new Nginx configuration file: nginx -c /etc/nginx/sites-available/mysite www2 www3 In this example, mysite is the name of a website. The www2 and www3 are the URLs for that website. 3. Type the following command to test your new Nginx configuration: nginx -t In this example, -t means “test”.
The worst part about making a mistake in your config files is that nginx will stop and it won’t start back up again until you fix the problem. So anybody trying to visit your site will get a fun error page.
So first you’ll want to figure out where nginx is located, which you can always do with a quick ps -ef | grep nginx (or many other methods that produce similar output).
So now that we know where the binary is located, just simply run it with the -t argument.
If you made a mistake, you’ll get an error message that indicates it failed.
If it succeeded, you’ll get a message that everything is fine.
So now that you know your syntax is correct, you can restart nginx (gracefully) by using service nginx reload. Or… you could chain them together so the reload happens but only if the syntax was correct, using the && operator like this:
It’s worth noting that your nginx might be located in a different folder, so you should adjust the path accordingly.