我正在努力https://mydomain.assuscomm.com/proxmox/重定向到安装我的 proxmox 虚拟机管理程序的内部 IP 和端口。
但是,只有当位置指令为“/”时,我才能使其工作。如果使用相同的配置,但将位置 URI 更改为“/proxmox/”或任何其他非 root 的 URI,我得到的只是一个空白页。似乎与 uri 的位置匹配成功,但重定向不知何故失败了。
例如以下配置失败:
server {
server_name mydomain.asuscomm.com;
auth_basic "Administrators Area";
auth_basic_user_file /etc/nginx/.htpasswd;
location /proxmox/ {
proxy_pass https://192.168.1.121:8006/;
proxy_redirect default;
proxy_buffering off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/mydomain.asuscomm.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mydomain.asuscomm.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = mydomain.asuscomm.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
server_name mydomain.asuscomm.com;
listen 80;
return 404; # managed by Certbot
}
但是,如果我将位置匹配更改为“/”(见下文),那么一切都会正常进行,并且我会成功重定向到 proxmox 登录页面。
我究竟做错了什么?
location / {
proxy_pass https://192.168.1.121:8006/;
proxy_redirect default;
proxy_buffering off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
答案1
location /proxmox/ {
rewrite ^/[^\/]+)(/.*) $1 break;
proxy_pass https://192.168.1.121:8006;
proxy_redirect default;
proxy_buffering off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
您需要rewrite
URI,否则目标服务器将尝试打开子目录,而该目录可能为空。