I've tried the following:
# this *should* serve the root from a static index.html file
location = / {
try_files $uri $uri.html $uri/ /index.html;
}
# resources are served directly by nginx
location /img {
}
location /css {
}
# all other URLs are served dynamically by nodejs
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Scheme $scheme;
}
The location /img
, location /css
and location /
clauses work.
I'm having trouble with location = /
. I added $uri $uri.html $uri/
because tryfiles
won't accept just /index.html
as a single argument.
Requests to /
are passed upstream, rather than being answered by nginx serving the (static) index.html file.
How can I redirect the root directory to the proxy server (NodeJS), while serving a literal '/' from a static file?