本文主要是介绍tomcat 和 nginx 做代理服务做结合请求,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
使用场景描述:
(1)用nginx做代理服务器,起并发作用
(2)用tomcat做应用服务器
(3)前端是https请求到nginx 并发服务器,然后nginx转为http请求到tomcat应用服务器
(4)正常访问应用服务器的应用,是界面显示正常(Java 程序,有使用jsp等)
在部署时所遇到的情况,jsp页面的请求为http,不是https,而nginx的代理服务器只接受https请求,导致界面显示不正常
解决方案:
(1)设置代理服务器的方法
nginx:
server {
8443
location ~* ^/ustore/
{
proxy_set_header Host $host:$server_port; ------->>
proxy_set_header X-Real-IP $remote_addr; ----->> 把真实的客户端请求ip存放在X-Real-IP 这个变量中
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; ---------->>把真实的ip地址增加到X-Forward-For 这个变量中
proxy_set_header X-Forwarded-Proto $schme; ------>> 真实的代码服务器 --------->>把真实的协议
proxy_redirect off;
proxy_connect_timeout 240;
proxy_send_timeout 240;
proxy_read_timeout 240;
proxy_pass http://upload.ustore.gb.com:28080;
}
}
配置Tomcat server.xml 的 Engine 模块下配置一个 Valve:
- <Valve className="org.apache.catalina.valves.RemoteIpValve"
- remoteIpHeader="X-Forwarded-For"
- protocolHeader="X-Forwarded-Proto"
- protocolHeaderHttpsValue="https"/>
<Connector port="28080" protocol="HTTP/1.1"
connectionTimeout="20000" URIEncoding="UTF-8"
redirectPort="8443" scheme="https" proxyPort="8443"/>
这篇关于tomcat 和 nginx 做代理服务做结合请求的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!