Nginx Tomcat的反向代理 [英] Nginx reverse proxy for tomcat
本文介绍了Nginx Tomcat的反向代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在使Nginx + tomcat 7反向代理设置正常工作时遇到问题.
I am having issues getting my nginx + tomcat 7 reverse proxy setup working.
基本上,我希望https://192.168.10.101
提供上游群集/webapp/中的内容;但是我从我的应用程序中获取了404页.
Basically I want https://192.168.10.101
to serve content from the upstream cluster/webapp/; However I am getting a 404 page from my applicaton.
任何关于出问题的提示将不胜感激.
Any hints on whats going wrong would be greatly appreciated.
我的配置如下.
server {
server_name 192.168.10.101;
access_log /var/log/nginx/mysite-access.log;
listen 443;
ssl on;
ssl_certificate /etc/nginx/ssl/mysite.crt;
ssl_certificate_key /etc/nginx/ssl/private/mysite_pvt.key;
location / {
proxy_redirect off;
proxy_pass https://tccluster/webapp/;
rewrite_log on;
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_max_temp_file_size 0;
}
}
upstream tccluster {
server 192.168.56.103:8443;
server 192.168.56.104:8443;
}
推荐答案
最后弄清楚了.该应用程序具有重定向到/webapp/index.html
的过滤器,该过滤器使nginx发出对提供404的/webapp/webapp/index.html
的请求.
Finally figured it out. The app has a filter that redirects to /webapp/index.html
, which made nginx make the request for /webapp/webapp/index.html
which was giving the 404.
我添加了重写规则
location / {
proxy_pass https://backend/webapp/;
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;
rewrite ^/webapp/(.*)$ /$1 last;
}
这似乎暂时有效!
这篇关于Nginx Tomcat的反向代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文