Home > OS >  Nginx Location Directive fail
Nginx Location Directive fail

Time:09-22

I'm trying this nginx.conf:

http {
    server {
        listen 80;

        location / {
            root /usr/share/nginx/html/;
        }

        location /pages/ {
            root /usr/share/nginx/html/static/;
        }
    }
}

Inside /usr/share/nginx/html/static/pages/ there is a file page1.html.

But, when I do GET /pages/page1.html, I receive this error: [error] 31#31: *2 open() "/usr/share/nginx/html/pages/page1.html" failed (2: No such file or directory), client: 172.17.0.1, server: , request: "GET /pages/page1.html HTTP/1.1", host: "localhost:8080".

Nginx is a dockerized container with port 8080 mapped to 80.

Why doesn't Nginx concatenate /static/ in the path?

CodePudding user response:

Based on recommendation made by @palindromeotter33, this is the answer:

http {
    server {
        listen 80;

        location / {
            root /usr/share/nginx/html/;
        }

        location /pages/ {
            alias /usr/share/nginx/html/static/pages/;
        }
    }
}
  • Related