我当前的nginx配置是这样的:
upstream nodejs { server 127.0.0.1:3000; } server { listen 8080; server_name localhost; root ~/workspace/test/app; index index.html; location / { proxy_pass http://nodejs; proxy_set_header Host $host ; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
我对nginx非常陌生,但是至少我知道nginx在提供静态文件方面比node / express好。如何配置服务器,以便Nginx提供静态文件?
我使用以下新配置解决了该问题:
upstream nodejs { server localhost:3000; } server { listen 8080; server_name localhost; root ~/workspace/test/app; location / { try_files $uri @nodejs; } location @nodejs { proxy_redirect off; proxy_http_version 1.1; proxy_pass http://nodejs; proxy_set_header Host $host ; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
感谢以下Stack Overflow帖子: