Reputation: 782
I've setup nginx for serving my node web app (api + web) but as I see the server is only responding to "/" (web root) calls. When I test it I see the main web page (located at /index.html) but with no images or css styles and also the api which is in route /api/v1/.... (/api/v1/users, /api/v1/cars and so on) can't be reached because nginx is responding "not found".
Current nginx configuration is:
server {
listen 80;
server_name localhost www.mydomain.com mydomain.com
access_log off;
error_log off;
location = / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
}
}
How can I configure nginx in order to serve all routes?
Upvotes: 2
Views: 1370
Reputation: 91749
To match all routes, drop the =
sign. Directives with the =
prefix will match queries exactly. More information can be found here.
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
}
Here's the samples from the documentation:
location = / {
# matches the query / only.
[ configuration A ]
}
location / {
# matches any query, since all queries begin with /, but regular
# expressions and any longer conventional blocks will be
# matched first.
[ configuration B ]
}
Upvotes: 3