I have sub-directories of html (containing summer.html) & images (containing summer.jpg which is referred to in summer.html) in my root nginx directory (/home/manager/www). Here is the relevant part of my server block (filename johnrose.mywire.org in sites available and and link to it in sites-enabled with certbot 'controlling' listening to it i.e. with lines in server block inserted by certbot:
server {
server_name johnrose.mywire.org;
root /home/manager/www;
location / {
try_files $uri $uri/ =404;
}
location /html/ {
alias /home/manager/www/html;
index index.html
try_files $uri $uri/ /html/index.html;
}
location /images/ {
alias /home/manager/www/images;
}
However, https:johnrose.mywire.org/summer.html fails to display 'stuff' from summer.html. Here is the relevant line from summer.html:
In summary: changed nginx server block to use alias for html sub-directory of nginx root, followed by restarting nginx which went Ok, but html did not display.
From alias:
When location matches the last part of the directive’s value:
location /images/ { alias /data/w3/images/; }
it is better to use the root directive instead:
location /images/ { root /data/w3; }
The location directive specifies the URL path component of the request being processed, and has nothing to do with the location of the file in the filesystem.
The root
and alias
directives convert the URL path component into a pathname that points to the file in the filesystem.
So, let's say you have two types of URL, those that begin with /images
and those that do not. For example:
https://example.com/foo
https://example.com/images/bar
The location /images/
block matches any URL that begins with /images/
and location /
block matches anything else.
You location /html/
is just wrong as it doesn't match your intended URLs, and is in fact a directory in your filesystem.
An example configuration:
root /home/manager/www/html/;
location / {
}
location /images/ {
root /home/manager/www/;
}
You could add try_files $uri $uri/ =404;
- but it is the default action for a location block anyway.