Ask a Question
Advertise on boostr.in
Organizational Research By
Surprising Reserch Topic
Is the Syntax of your Web Server Configuration File Correct?
If your web server refused to start, often this is an indication that your configuration files need some attention. Both Apache and Nginx require strict adherence to their directive syntax in order for the files to be read.
The configuration files for these services are usually located within a subdirectory of the /etc/ directory named after the process itself.
Thus, we could get to the main configuration directory of Apache on Ubuntu by typing:
In a similar way, the Apache configuration directory on CentOS also mirrors the CentOS name for that process:
The configuration will be spread out among many different files. If your service failed to start, it will usually point you to the configuration file and the line where the problem was first found. Check that file for errors.
Each of these web servers also provide you with the ability to check the configuration syntax of your files.
If you are using Apache, you can use the apache2ctl or apachectl command to check your configuration files for syntax errors:
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
As you can see above, we've received an informational message about a detail in our configuration, but there were no errors. This is good.
If you have an Nginx web server, you can run a similar test by typing:
sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
As you can see, this process checks your syntax as well. If we remove an ending semi-colon from a line in the file (a common error for Nginx configurations), you would get a message like this:
sudo nginx -t
nginx: [emerg] invalid number of arguments in "tcp_nopush" directive in /etc/nginx/nginx.conf:18
nginx: configuration file /etc/nginx/nginx.conf test failed
There is an invalid number of arguments because Nginx looks for a semi-colon to end statements. If it doesn't find one, it drops down to the next line and interpret that as further arguments for the last line.
You can run these tests in order to find syntax problems in your files. Fix the problems that it references until you can get the files to pass the test.
Aug 29, 2015
to add a comment.
Related Hot Questions
Your name to display (optional):
Email me at this address if my answer is selected or commented on:
Email me if my answer is selected or commented on
Privacy: Your email address will only be used for sending these notifications.
To avoid this verification in future, please