How to get host name with port from a http or https request

前端 未结 7 792
没有蜡笔的小新
没有蜡笔的小新 2020-12-02 22:22

I have two applications deployed in jboss container(same unix box). If i get a request from app1, i need to frame a corresponding request for app2.

eg:

7条回答
  •  醉梦人生
    2020-12-02 23:18

    If you use the load balancer & Nginx, config them without modify code.

    Nginx:

    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_set_header X-Forwarded-Proto  $scheme;  
    

    Tomcat's server.xml Engine:

     
    

    If only modify Nginx config file, the java code should be:

    String XForwardedProto = request.getHeader("X-Forwarded-Proto");
    

提交回复
热议问题