我一直在寻找,但没有找到一个人在不使用子域的情况下在同一台服务器上托管多个节点站点。我想要类似以下内容...
website.com/app1 - > 127.0.0.1:3000
website.com/app2 - > 127.0.0.1:9000
upstream node {
server 127.0.0.1:3000;
keepalive 64;
}
server {
listen 80;
server_name webaddress.com;
root /var/www/trucks/;
location /livereload {
proxy_pass http://localhost:35729;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
location /app1 {
rewrite ^/app1/?(.*) /$1 break;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://127.0.0.1:3000;
root /var/www/trucks;
}
我甚至尝试过重写请求;然而,这似乎没有任何影响。如果我删除/ app1它可以正常工作。我得到的最接近的是转发到多个站点,但当地快递路线无效。
答案 0 :(得分:1)
我的工作设置如下:
server {
listen 8080;
server_name localhost;
location / {
proxy_pass http://localhost:3000;
proxy_set_header Host $host;
}
location /api {
proxy_pass http://localhost:3001;
rewrite ^/api(.*) /$1 break;
proxy_set_header Host $host;
}
}
答案 1 :(得分:0)
您是否尝试使用proxy_redirect
指令而不是rewrite
?
http://wiki.nginx.org/HttpProxyModule#proxy_redirect
答案 2 :(得分:0)
答案 3 :(得分:0)
您的配置问题是您正在使用websockets应用程序代理进行代理的常规http应用程序混合。没有必要使用重写。这是我能想到的最简单的配置:
server {
listen 80;
index index.html index.htm;
server_name _;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
location /node1 {
proxy_pass http://localhost:8888;
}
location /node2 {
proxy_pass http://localhost:9999;
}
}
我建议你在nginx网站上更改websockets相关文档: http://nginx.org/en/docs/http/websocket.html