In this recipe, we will cover some common issues with Apache and Nginx and list the basic steps for overcoming those issues. The steps mentioned here are general troubleshooting methods; you may need to change them based on your setup and environment.
Web server problems can be grouped in a few broad categories, such as a server not working, a particular domain or virtual host is not accessible, problems with a specific module configuration, and access denied errors. The following section lists each of these problems and their possible solutions.
telnet
connection to web server on port 80
, or whatever port you have used for web server. If you see output similar to following screenshot, then your web server is working:$ sudo netstat -plutn
$ sudo service apache2 reload/restart
/var/log/
directory and view the entire file in a scrollable format:$ less /var/log/apache2/error.log
$ tail -f /var/log/nginx/error.log
LogLevel
in /etc/apache2/apache2.conf
and set its value to debug
:$ sudo nano /etc/apache2/apache2.conf LogLevel debug
$ sudo apache2ctl -X # debug mode single worker
ubuntu@ubuntu:~$ a2query -s example.com (enabled by site administrator)
ubuntu@ubuntu:~$ sudo apache2ctl -t Syntax OK
ubuntu@ubuntu:~$ sudo nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
$ sudo apache2ctl -S
NamedVirtualHost
.DocumentRoot
- does it point to proper files?<VirtualHost *:80> DocumentRoot /var/www/html <VirtualHost>
server { root /usr/share/nginx/html; }
ServerName
and ServerAlias
variables - do they match your domain name?<VirtualHost *:80> ServerName example.com ServerAlias www.example.com </virtualHost>
ServerName
is defined as this:server { server_name example.com www.example.com; }
Check directory permissions for the virtual host root directory. Are they accessible to the web server? Check the web server user and group (commonly www-data
) have ready permissions. If required, you can set permissions with chown
and chmod
commands.
ubuntu@ubuntu:~$ ls -l /var/www/ drwxr-x--- 3 ubuntu www-data 4096 Aug 4 23:00 example.com drwxr-xr-x 2 ubuntu www-data 4096 Aug 2 23:04 public_html
Secondly, make sure that you have properly set directory permissions in the virtual host configuration. Are they restricting file access?
Use the following commands to set directory permissions in the virtual host configuration:
<Directory /var/www/> AllowOverride None Order Deny,Allow Deny from all </Directory>