0

I've installed Nginx on my Digital Ocean droplet and I've done a build for my react application, now I want to serve the build index.html file to Nginx,

/etc/nginx/sites-enabled/default:

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

        root /root/project-name/dist;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }
}

When I visit the server in the browser I get an 404 message.

The path /root/project-name/dist is valid:

enter image description here

If I change the root path to:

root /var/www/html;

Then I get the default Nginx page displayed:

enter image description here

The root and var folder are both in the same path:

enter image description here

So why can't I point my root to a different folder?

Peter Boomsma
  • 8,851
  • 16
  • 93
  • 185

1 Answers1

0

Resolved the error.

Step 1. Read the logs (!!)

Nginx: stat() failed (13: permission denied)

My nginx logs are located in /var/log/nginx/. The error.log showed:

2021/10/04 18:18:41 [crit] 1565#1565: *3 stat() "/root/project-name/dist/" failed (13: Permission denied), client: 82.73.195.213, server: _, request: "GET / HTTP/1.1", host: "104.248.82.123"

Step 2. Change access to folders:

chmod +x /root/
chmod +x /root/project-name
chmod +x /root/project-name/dist
Peter Boomsma
  • 8,851
  • 16
  • 93
  • 185