Debugging nginx server block configuration

July 14, 2015 1.5k views

I'm trying to set up a very basic configuration to put a static website online.

I have a domain registered and I configured the nameserver on the domain provider and added it to the droplet.

I followed this tutorial:

and created a virtual host configuration for the website exactly like in the tutorial. It doesn't work, I just get an "Unable to connect" error. I also made sure to remove the "default" configuration from the sites-enabled directory, but still the same.

I decided to go back to the basics and started reading this guide:

I managed to make it working just with these lines inside nginx.conf:

server {
location / {
root /var/www/;

I want to be able to put the configuration in separate files inside sites-availabel, though, so I tried again copying just the above lines, but nothing. Also, when the page fails to load nothing gets logged.
I checked the configuration with sudo nginx -t and it says it's ok. Where and how can I start debugging it?

Thanks for your help

6 Answers

No problem, good you checked the nginx configuration again. I thought you followed the DO tutorial so didnt put any attention to that, good you solved it.

Yes thats how links are supposed to be created, your server needs to know the absolute path to create a link. Otherwise it could also "search and find" a same named directory somewhere else that you dont want to link. So now it was linking a sites-available/ in the root directory. I hope this explaines your questions, for any more questions I'll be happy to help you.

Please post the vhost of one of your test websites here, and the directory where you got this first website index.html.

How do you connect to your website? With the domain name or IP? Please post your domainname and how you got this setup, the records where and how.

  • this is the vhost inside sites-available:

    server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;
        root /var/www/;
        index index.html index.htm;
        location / {
            try_files $uri $uri/ =404;

    it is linked in sites-enabled.

    the index.html file is in /var/www/

    In this case I'm trying to connect to the website typing the address

"the index.html file is in /var/www/"
If your index.html is in there, why do you have the vhost root at /var/www/

  • sorry, I just misstyped it: the file is actually in /var/www/

Allright, I am working from my Ipad now so I am not very fast and I can't check alot of things. But from my diagnotics something is wrong with your server/nginx service. I checked your DNS and nothing is wrong with that, also your vhost looks good but you can try to run nginx without the ipv6 option.

Anyway what doesnt look good is your webserver. Port 80 isnt open or isnt being used by nginx. Check your nginx configuration to be sure it is running on port 80. Also check your firewall if youre running one, to make sure port 80 is open.

  • thanks for your help.
    While looking for this issue related to the port I stumbled on another post that helped me. Apparently the problem was in the way I created the link.
    I used to do it with relative paths, like this:

    ln -s sites-available/ sites-enabled/

    And this way the link wasn't working. Using absolute paths actually solved the issue. Is this normal? I mean, is this how links are supposed to work or it's some weird bug?

I would be interested in knowing how did you do the diagnostics on my server. So to learn something useful for the future

Have another answer? Share your knowledge.