我在我的服务器上运行Nginx ansel.ms和ansel.ms:46156上的一个node.js应用程序.
ansel.ms/rhythm
@H_301_10@至
ansel.ms:46156. ansel.ms/rhythm/sub/path
@H_301_10@应该成为
ansel.ms:46156/sub/path
@H_301_10@这是我的文件在网站可用:
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; } }
@H_301_10@我真的不明白这是做什么(proxy_set_header的东西),我只是复制&从几个来源粘贴它.
它不工作
你能给我一个提示什么改变,所以这是我上面描述的?
谢谢!
最佳答案
我无法发现您的配置文件中的错误;我也是一个Nginx-newbie.
但是这里是我的完整的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; } } }
@H_301_10@这不是完美的,因为它不会与http:// myhost / cabaret一起工作,只有如果在如下http:// myhost / cabaret /或http:// myhost / cabaret / foo / bar之后的一个斜杠.