我尝试将在端口8002上运行的大量网络客户端代理转发到某个位置/deluge
,并将其余位置/
提供给目录。
upstream deluge {
server 127.0.0.1:8002;
}
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
index index.html index.htm;
server_name localhost;
location / {
root /home/ubuntu/web;
autoindex on;
try_files $uri $uri/ =404;
}
location /deluge {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://deluge;
}
}
我验证了是否正在运行deluge-web:
root:~# ps -aux | grep deluge
root 7652 0.0 0.2 67896 2200 pts/0 S 23:20 0:00 sudo nohup deluge-web -p 8002
root 7653 0.0 2.2 72488 22832 pts/0 S 23:20 0:00 /usr/bin/python /usr/bin/deluge-web -p 8002
root 7743 0.0 0.0 10464 936 pts/0 S+ 23:31 0:00 grep --color=auto deluge
Visting http://xx.xx.xx.xx/
运行正常。但访问http://xx.xx.xx.xx/deluge
会引发404错误:
No Such Resource
No such child resource.
答案 0 :(得分:2)
我认为这就是答案!
Correct proxy path in nginx.conf
您希望在location和proxy_pass的末尾添加斜杠,以便它也不会重定向该位置。
pasted from answer-
location /test/ {
proxy_pass http://localserver.com/;
}
nginx does NOT replace URI path part if the proxy_pass directive does not have a URI path itself. So my fix of adding a slash (slash is treated as a URI path) at the end triggers the URI path replacement.
Reference: http://wiki.nginx.org/HttpProxyModule#proxy_pass
If it is necessary to transmit URI in the unprocessed form then directive >proxy_pass should be used without URI part