404 on non root '/' NginX location

by Stephane   Last Updated September 11, 2019 10:00 AM

I have a text file that is served fine from the root /hi.txt URL but not from a /test/hi.txt URL.

Here is the full NginX configuration:

server {
    listen 80;
    server_name xxx.com *.xxx.com;
    server_tokens off;

    root /var/www/certbot;

    location /test {
        root /var/www/certbot;
    }
}

UPDATE: I would like to have the file not 404 on the http://example.com/test/hi.txt request.

UPDATE II: I now understand more on the issue. The error log shows:

open() "/var/www/certbot/test/hi.txt" failed (2: No such file or directory),

I thought the /test location was NOT suffixed to the root.

Is there any way NOT to suffix the /test location ?

Tags : nginx


Answers 2


You can use an alias here, like:

location /test {
        alias /var/www/certbot;
}

See here: http://nginx.org/en/docs/http/ngx_http_core_module.html#alias

g_bor
g_bor
September 11, 2019 09:50 AM

Using an alias and not having any trailing slash / character in the location path, had the file served fine:

location /test {
    alias /var/www/certbot;
}
Stephane
Stephane
September 11, 2019 09:51 AM

Related Questions



nginx location not opening static site

Updated August 03, 2019 14:00 PM


Nginx: alias and try_files with $args

Updated March 26, 2015 14:00 PM