使用 Nginx 的多节点应用程序
Mutliple Node app with Nginx
我想 运行 多节点应用程序通过 Nginx 服务器作为反向代理。我的配置文件中实际上有类似的东西:
server {
listen 80;
server_name http://my.server.url;
location / {
root /absolute/path/to/index/;
index index.html;
}
location /foo/ {
proxy_pass http://127.0.0.1:3000; # here is an nodejs app runing
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
问题:在我的 nodejs 应用程序中,我收到 url 之前的 '/foo/'。
我试着用重写来胡闹,但老实说我很困惑,所以我想得到 '/bar/' 而不是 '/foo/bar/',我应该如何进行?
你需要的在nginx
中调用rewrite
location /foo/ {
rewrite ^/foo(.*)$ / last;
proxy_pass http://127.0.0.1:3000; # here is an nodejs app runing
}
我想 运行 多节点应用程序通过 Nginx 服务器作为反向代理。我的配置文件中实际上有类似的东西:
server {
listen 80;
server_name http://my.server.url;
location / {
root /absolute/path/to/index/;
index index.html;
}
location /foo/ {
proxy_pass http://127.0.0.1:3000; # here is an nodejs app runing
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
问题:在我的 nodejs 应用程序中,我收到 url 之前的 '/foo/'。 我试着用重写来胡闹,但老实说我很困惑,所以我想得到 '/bar/' 而不是 '/foo/bar/',我应该如何进行?
你需要的在nginx
中调用rewritelocation /foo/ {
rewrite ^/foo(.*)$ / last;
proxy_pass http://127.0.0.1:3000; # here is an nodejs app runing
}