gpt4 book ai didi

tomcat - nginx 代理添加 servlet 路径

转载 作者:行者123 更新时间:2023-11-28 23:49:11 25 4
gpt4 key购买 nike

我有 Tomcat 6 在路径“be”上运行 Web 应用程序。 Spring Security 用于登录过程。登录网址为 /console/login并重定向到 /console/customer登录后。我将 https 用于 login customer 的 url 和 http网址。我没有在任何 spring 配置文件中指定 servlet 路径。在访问 /be/console/login 后一切正常收到正确的重定向(至 /be/console/customer)。

现在我想要一个代理。我将 Nginx 配置为转发 https://localhosthttps://<someip>:9443 http也是一样,从80端口转发到9080端口。

问题是 Nginx 向浏览器返回无效的重定向。相反 /be/console/customer它返回 /be/be/console/customer . Servlet 路径被添加到 URL 两次。

如何删除第二个“be”?

谢谢。

Nginx 配置:

server {
listen 443 ssl;
server_name localhost;

ssl on;
ssl_certificate C:\jc\\nginx\\tc\selfsigned.cer;
ssl_certificate_key C:\jc\\nginx\\tc\private.key;

ssl_session_timeout 5m;

ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;

location / {
proxy_redirect off;
proxy_pass https://<some ip>:9443;
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;
}

location ~ /.+ {
proxy_redirect off;
proxy_pass https://<some ip>:9443;
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;
}
}
server {
listen 80;
server_name localhost;

access_log logs/access.log;
error_log logs/error.log;

location / {
proxy_redirect off;
#server_name_in_redirect off;
proxy_pass http://<some ip>:9080;
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;
}

location ~ /.+ {
proxy_redirect off;
proxy_pass http://<some ip>:9080;
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;
}
}

最佳答案

此配置在生产中有效:

location /demo/ {
proxy_pass http://localhost:8080;
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;
proxy_pass_request_headers on;

client_max_body_size 10m;
client_body_buffer_size 128k;

proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;

proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}

关于tomcat - nginx 代理添加 servlet 路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11033746/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com