Nginx Troubleshooting

I'm noticing some issues with nginx. What are the best ways for me to go about troubleshooting this?

1 Reply

Below you'll find some basic Nginx troubleshooting tips. These are a great place to start if you're having issues with your web server and cannot determine the problem, and feel free to add any suggestions or experiences you've had with troubleshooting Nginx.


To set, let's ensure Nginx is actually running. You'll be able to use one of the following commands depending on your distribution:
sudo service nginx status
sudo systemctl status nginx

If Nginx is not running then start it with:
sudo service nginx start
sudo systemctl start nginx

A common problem is running multiple web severs at once. While this is doable, it requires a specific configuration that you or your admin should already be aware of. You can check if you're accidentally running two web servers by using the below commands to see if Apache, which is another common web server, is running:
sudo service apache2 status
sudo systemctl status apache2

If Apache is running and it shouldn't be, then stop it with:
sudo service apache2 stop
sudo systemctl stop apache2

So at this point, Nginx should be running; what's next? Let's confirm it's listening for connections. Older distributions will use netstat, whereas ss has become the standard on newer systems. Run the following to see if Nginx is listening for connections:
sudo nestat -plunt
sudo ss -plunt

If Nginx is listening, but you cannot connect, then you may have a firewall problem. Check out the link[1] at the bottom of this page as it covers common firewall mistakes.

If Nginx is up and running and it's listening for connections, then we can move on to the access and error logs. These are typically found in the following locations, though custom log files are possible.
/var/log/nginx/access.log
/var/log/nginx/error.log

Both of those logs will display helpful information, and you can use either the tail command or less to view those files. Assuming those log files show no errors, you have two more good starting points. The first is a configuration test built into Nginx. This can be run with:
sudo nginx -t

And will output the following if everything is OK(I'm using a default Nginx config):

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

The second is to confirm your server's permissions are correct. What's "correct" here really depends on your setup, and there are many online guides that cover this topic, so I recommend you go explore all the possible options. Our Users and Groups guide is a great place to start.


Finally, your greatest resource for troubleshooting Nginx is the documentation provided at Nginx.com. Here are a few links to get you started, and there's certainly more on that site you can dig into.


Related Posts:

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct