我只是尝试使用 proxy_pass 为我的域创建一个特定位置:
location /new/ {
proxy_pass http://192.168.9.6:10061;
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_redirect off;
}
http://我的网站/new/应指向机器 192.168.9.6 上打开的 10061 端口的服务。
但事实并非如此,我只是遇到了 404。
如果我在这个位置放置一个return 403
,我就会遇到一个禁止访问的情况,所以位置是可以的,但是这个proxy_pass
没有效果。
事实是,这是有效的:
location / {
proxy_pass http://192.168.9.6:10060;
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_redirect off;
}
2 个端口上的服务是同一种,唯一的区别是 /new 与 root。所以我不明白我误解了什么。
编辑:
当我访问 domain.com/new 时,我在 nginx 日志中看到的内容如下:
xx.xx.xx.xx - - [17/May/2018:14:16:35 +0200] "GET /new/ HTTP/1.1" 404 209 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:59.0) Gecko/20100101 Firefox/59.0"
这是192.168.9.6的登录服务器:
2018-05-17 12:16:36,806 1 INFO p2plegal werkzeug: 192.168.9.1 - - [17/May/2018 12:16:36] "GET /new/ HTTP/1.0" 404 -
这是该域的完整 nginx 配置:
upstream manage-old {
server 192.168.9.6:10060; #Production
}
upstream manage-new {
server 192.168.9.6:10061; #Production
}
server {
server_name manage.mydomain.com;
listen 443 ssl;
listen [::]:443 ssl;
location / {
proxy_pass http://manage-old;
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_redirect off;
}
location /new/ {
proxy_pass http://manage-new;
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_redirect off;
}
location ~ /web/database/manager {
auth_basic "Admin only";
auth_basic_user_file /etc/nginx/.htpasswd-admin;
proxy_pass http://manage-old;
}
location ~ /web/database/selector {
auth_basic "Admin only";
auth_basic_user_file /etc/nginx/.htpasswd-admin;
proxy_pass http://manage-old;
}
ssl_certificate /etc/letsencrypt/live/manage.mydomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/manage.mydomain.com/privkey.pem;
}
server {
if ($host = manage.mydomain.com) {
return 301 https://$host$request_uri;
}
server_name manage.mydomain.com;
listen 80;
return 404;
}