我想通过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应用中,我收到了' / foo /'之前。 我试着用重写来喋喋不休,但老实说我很困惑,所以我想得到' / bar /'而不是' / foo / bar /',我该怎么办?
答案 0 :(得分:0)
您需要的是nginx中的rewrite
location /foo/ {
rewrite ^/foo(.*)$ /$1 last;
proxy_pass http://127.0.0.1:3000; # here is an nodejs app runing
}