Answer the question
In order to leave comments, you need to log in
Why is static not given?
Hello. Tried to set up nginx on localhost and ran into a problem. The static is returned, all requests are proxied, but when visiting localhost:3000 index.html is not displayed (instead I see 404 page not found).
When visiting localhost:3000/index.html everything is fine. Here is nginx.conf
server {
# IP, который мы будем слушать
listen 127.0.0.1:3000;
location / {
# IP и порт, на которых висит node.js
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
root /home/www/files;
index index.html;
}
location ~ \.(html|css|js)$ {
access_log off;
expires 30d;
root /home/www/files/;
}
}
Answer the question
In order to leave comments, you need to log in
The config is normal, everything works exactly as you wrote. The request to/goes to 127.0.0.1:8080. The request for /index.html goes to another location and is returned statically. Since you did not describe how the system should behave, which requests should be static, which - dynamics, then there is no possibility to offer another config.
PS;
Option 1. Describe / as a separate exact match location
root /home/www/files;
location = / {
index index.html;
}
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~ \.(html|css|js)$ {
access_log off;
expires 30d;
}
root /home/www/files;
location / {
try_files $uri $uri/ @nodejs;
index index.html;
}
location @nodejs {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~ \.(html|css|js)$ {
access_log off;
expires 30d;
}
root /home/www/files;
location / {
try_files $uri /index.html @nodejs;
}
location @nodejs {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~ \.(html|css|js)$ {
access_log off;
expires 30d;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question