tomcat 和 nginx 做代理服务做结合请求,tomcatnginx


使用场景描述

(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:

Xml代码  
  1. <Valve className="org.apache.catalina.valves.RemoteIpValve"  
  2. remoteIpHeader="X-Forwarded-For"  
  3. protocolHeader="X-Forwarded-Proto"  
  4. protocolHeaderHttpsValue="https"/>  


<Connector port="28080" protocol="HTTP/1.1"
               connectionTimeout="20000" URIEncoding="UTF-8"
               redirectPort="8443" scheme="https"  proxyPort="8443"/>


相关内容

    暂无相关文章