如何使用nginx将address.com/foo/barredirect到address.com:port/bar?

我在我的服务器上运行nginx ansel.ms和ansel.ms:46156上的node.js应用程序。

我想设置nginx,所以它redirect的一切

ansel.ms/rhythm 

 ansel.ms:46156. ansel.ms/rhythm/sub/path 

应该成为

 ansel.ms:46156/sub/path 

这是我的网站可用的文件:

 upstream rhythm { server ansel.ms:46156; } server { listen 80; server_name ansel.ms www.ansel.ms; access_log /srv/www/ansel.ms/logs/access.log; error_log /srv/www/ansel.ms/logs/error.log; location / { root /srv/www/ansel.ms/public_html; index index.html index.htm; } location ~ \.php$ { include fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /srv/www/ansel.ms/public_html$fastcgi_script_name; } location /rhythm{ 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://rhythm; proxy_redirect off; } } 

我真的不知道这是什么(proxy_set_header的东西),我只复制和粘贴来自多个来源。

它不起作用。

你能给我一个提示什么改变,所以它做我上面描述的? 谢谢!

我不能发现你的配置文件中的错误; 我也是一个nginx的新手。

但是这里是我完整的nginx.conf配置文件,它将http://myhost/cabaret/foo/bar重定向到http://myhost:8085/foo/bar

 user www-data; worker_processes 1; error_log /var/log/nginx/error.log; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; access_log /var/log/nginx/access.log; sendfile on; keepalive_timeout 65; tcp_nodelay on; server { listen *:80; ## listen for ipv4 access_log /var/log/nginx/localhost.access.log; location /cabaret { rewrite /cabaret(.*) $1 break; proxy_pass http://127.0.0.1:8085; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } } 

这不是完美的,因为它不会与http://myhost/cabaret carabet ,只有在http://myhost/cabaret/ carabet http://myhost/cabaret/http://myhost/cabaret/foo/bar carabet类的斜杠。