What am I doing wrong here?
This works:
location / {
alias /var/www/static/;
try_files $uri index.html =404;
}
But this doesn't:
location /hello {
alias /var/www/static/;
try_files $uri index.html =404;
}
Here is the error I'm getting:
[error] 14428#0: *1 open() "/usr/share/nginx/html/bundle.js" failed (2: No such file or directory)
I know that Nginx is looking for bundle.js from the wrong directory. It should be located in the /var/www/static/ folder.
I can fix that by adding
root /var/www/static/
in the beginning of my config but then if I add another location the same problem re-emerges.
location /world {
alias /var/www/another/;
try_files $uri index.html =404;
}
Error:
[error] 14827#0: *1 open() "/var/www/static/bundle2.js" failed (2: No such file or directory)
bundle2.js should be in the /var/www/another/ folder but because I defined root as /var/www/static/ Nginx is looking for bundle2.js from the wrong folder.
Here is the whole config:
server {
listen 80;
root /var/www/static/;
location /hello {
alias /var/www/static/;
try_files $uri index.html =404;
}
location /world {
alias /var/www/another/;
try_files $uri index.html =404;
}
}