【发布时间】:2015-05-22 20:56:20
【问题描述】:
我在一个 nginx .conf 文件中有多个位置,就像这样。
server {
...
location /api/ {
client_max_body_size 0;
proxy_pass http://127.0.0.1:8000/api/;
proxy_redirect off;
proxy_read_timeout 5m;
proxy_set_header Host $host;
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header XForwardedFor $proxy_add_x_forwarded_for;
}
...
location /cliente/ {
proxy_pass http://127.0.0.1:4000/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header HOST $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_redirect off;
}
location / {
proxy_pass http://127.0.0.1:8000/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header HOST $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_redirect off;
}
在大多数情况下,位置是节点服务器,为他自己的静态文件和 api rest 提供服务。
每个节点应用程序中的静态文件正在加载使用 html 文件并调用如下
/my-static-path-1/
/my-static-path-2/
问题:
当服务器尝试加载一个直接从/ 加载的路径时,不使用自己的子路径,导致 404 错误。
示例:
1) url http:/myip_sample.com/cliente 调用 nodejs 应用程序来提供一个 html 文件,该文件需要加载一个 css 脚本,如 /my-static-path/js/sample.js。
2) 此文件调用 http:/myip_sample.com/my-static-path/js/sample.js 而不是 http://myip_sample.com/cliente/my-static-path/js/sample.js
我想在不改变任何东西的情况下这样做,只使用 nginx conf 文件。
提前致谢!
【问题讨论】:
-
你可以从它自己的位置提供静态 /my-static-path-1/ { root /var/static/;} nginx.com/resources/admin-guide/serving-static-content
标签: javascript node.js nginx location static-files