[英]Nginx proxy for node.js app error: Failed to load resource
我有两个node.js应用程序:一个是我的网站,第二个是CI工具。 我有以下nginx配置:
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://127.0.0.1:8081/;
}
location /ci {
rewrite ^/ci(.*) /$1 break;
proxy_pass http://127.0.0.1:3000/;
}
}
当我在浏览器中打开example.com时,它会正确加载index.html请求的所有资源,但是当我打开example.com/ci时,它仅加载index.html,并且出现如下错误:
GET http://example.com/styles/styles.css 404
GET http://example.com/scripts/app.js 404
我在CI应用程序的index.html头中添加了<base href="/ci">
,但这没有帮助。
我结束了下一个nginx配置:
server {
listen 80;
server_name example.com;
location / {
if ($http_referer ~* example.com/ci) {
rewrite (.*) http://example.com/ci$1;
}
access_log off;
proxy_pass http://127.0.0.1:8081/;
proxy_set_header Host $host;
proxy_buffering off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location = /ci { rewrite ^ /ci/ last; }
location /ci/ {
access_log off;
proxy_pass http://127.0.0.1:3000/;
proxy_set_header Host $host;
proxy_buffering off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
同样在我的CI应用程序的客户端上,我为socket.io连接指定了域和端口: io.connect('http://example.com:3000')
。 不需要<base>
html标记。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.