Skip to content

NGINX

Other Resources

How to Test NGINX Config

It’s important to test your NGINX configuration to prevent downtime. If you make a syntax error, your restart will fail and your site will go down. Fortunately it’s really easy to test your configuration before reloading.

nginx logo

Test Default Config

				
					> nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
				
			

The NGINX command will test the default configuration files without affecting your NGINX service. You receive error information and details on which files were checked.

Config Errors

If NGINX detects an error in your configuration file, you will get output like the following:

				
					> nginx -t
nginx: [emerg] unexpected "}" in /etc/nginx/nginx.conf:119
nginx: configuration file /etc/nginx/nginx.conf test failed
				
			

This error tells us there is something unexpected at /etc/nginx/nginx.conf on line 119. If we open that file we should be able to track down the issue and try again.

Common Errors

There are few things to check when you get an error:

  1. Missing braces: This is one of the most common issues. Ensure each block has an opening and closing brace. For example, ensure your server block starts with a brace and ends with one.
  2. Missing semicolon: Each of your directives (e.g. server_name) should end with a semicolon. It’s just like writing C code.
Ready to get the whole story on your uptime?
 
Status List delivers uptime checks with technical diagnostics in a one dashboard. A pass/fail isn’t the whole story.
 
Join over 2,000 companies and try it for free today.

Testing Custom Config File

You can also test config files in non-standard locations. This can be especially helpful if you’re running Docker. Simply pass the “-c” option to your NGINX command. See below for an example:

				
					> nginx -t -c /opt/mynginx.conf
nginx: the configuration file /opt/mynginx.conf syntax is ok
nginx: configuration file /opt/mynginx.conf test is successful
				
			

More Reading

Optimized with PageSpeed Ninja