Nginx 403 Forbidden error on a simple conf file

October 6, 2019 104 views
Nginx

I’ve got a new Ubuntu 18.04 droplet on DO, by following this guide. Just installed Nginx and Ufw (which is disabled for now) on it. I’ve this conf file inside the /etc/nginx/conf.d folder.

server {
    listen 80 ;
    listen [::]:80 ;

        root /var/www/2;
        index index.html index.htm index.nginx-debian.html;

        server_name 2.hotelbobbygg.xyz;

        location / {
                try_files $uri $uri/ =404;
        }
}

In the error log, this is written *7 directory index of "/var/www/2/" is forbidden, client: 139.5.37.198, server: 2.hotelbobbygg.xyz, request: "GET / HTTP/1.1", host: "2.hotelbobbygg.xyz"

I’ve also tried commenting out the 3rd line from last, i.e. try_files line. But it still behaves the same. Pls help what is preventing me to access the index.html lying inside /var/www/2 folder.

And if I used below given text in that ../conf.d/2.conf file (replacing what is already there), then also it doesn’t succeed (rather falls back on serving the /usr/share/nginx/html/index.html).

server {
        listen 80; listen [::]:80;
        server_name 2.hotelbobbygg.xyz;  # <-- change this

        location /.well-known/acme-challenge/ {
                root /var/www;
        }

        location / {
                return 301 https://$host$request_uri;
        }
}

2 Answers

Hello, @zopfans

Can you check the site configuration file and make sure everything is okay? The one in:

/etc/nginx/sites-available/

and see the root directory of the site itself. Let me know how it goes.

I deleted that ‘default’ file (or its link in the sites-enabled).

Index file is serving ok from that very location /var/www/2.
I’ve copied that very file from some other working locations.

Have another answer? Share your knowledge.