nginx HttpProxyModule 配置帮助
我正在尝试使用 nginx 在允许访问 H2 数据库 Web 控制台之前强制执行基本身份验证。该控制台运行在 https://localhost:8084
在我的 nginx.conf 中,我有:
location /h2 {
auth_basic "Restricted";
auth_basic_user_file htpasswd;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_pass https://localhost:8084/;
}
我想要它做什么是对 /h2 到 H2 网络服务器的代理请求。此配置适用于第一个请求,但是 H2 服务器立即发送“/login.jsp”的 HTTP 重定向,该重定向作为“/login.jsp”而不是“/h2/login.jsp”发送到我的浏览器。这意味着当我的浏览器请求该页面时,请求失败,因为只有位置“/h2”处的 url 被传递到 H2 网络服务器。
如何将“/h2”附加到 H2 网络服务器返回的任何重定向中?我尝试了以下操作:
proxy_redirect https://localhost:8084/ https://$host/h2;
但它没有做任何事情。
I am trying to use nginx to enforce basic authentication before allowing access to the H2 database web console. This console is running on https://localhost:8084
In my nginx.conf, I have:
location /h2 {
auth_basic "Restricted";
auth_basic_user_file htpasswd;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_pass https://localhost:8084/;
}
What I want it to do is proxy requests for /h2 to H2's webserver. This configuration works for the first request, however the H2 server immediately sends a HTTP redirect for "/login.jsp" which is getting sent to my browser as "/login.jsp" and not "/h2/login.jsp". This means that when my browser requests the page, the request fails because only urls at location "/h2" get passed to the H2 webserver.
How can I append "/h2" to any redirects returned by the H2 webserver? I tried the following:
proxy_redirect https://localhost:8084/ https://$host/h2;
but it didnt do anything.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这似乎是 nginx 配置问题。尝试在 nginx.conf 中使用
location /h2/
(带有尾部斜杠)而不是location /h2
。然后连接到http://localhost/h2/
。您不需要任何反向代理配置,因为 H2 控制台工具不使用绝对 URL(它重定向到“login.jsp”而不是“/login.jsp”)。问题是 http://localhost:/h2 是一个“文件名”,而 http://localhost:/h2/ 是一个“目录”。This seems to be a nginx config problem. Try
location /h2/
(with trailing slash) instead oflocation /h2
in the nginx.conf. And then connect tohttp://localhost/h2/
. You don't need any reverse-proxy config, as the H2 Console tool doesn't use absolute URLs (it redirects goes to "login.jsp" and not to "/login.jsp"). The problem is that http://localhost:/h2 is a 'file name', whereas http://localhost:/h2/ is a 'directory'.