nginx反向代理到tomcat,并在request中获取客户端请求ip

 #配置一个代理即tomcat1服务器  
        upstream tomcat_server1 {  
            server 192.168.0.106:8080;  
        }  
          

          
#配置一个虚拟主机  
        server {  
            listen 80;  
            server_name www.test1.com;  
            location / {  
                    #域名www.test1.com的请求全部转发到tomcat_server1即tomcat1服务上  
                    proxy_pass http://tomcat_server1;  
                    #欢迎页面,按照从左到右的顺序查找页面  
                    index index.jsp index.html index.htm;  
            }  
  
        }  
          
       

 配置获取ip

nginx反向代理配置时,一般会添加下面的配置:

      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header REMOTE-HOST $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

 

location / {

   proxy_pass http://127.0.0.1:10678;

   proxy_set_header Host $host;

        proxy_set_header X-Real-IP $remote_addr;

        proxy_set_header REMOTE-HOST $remote_addr;

        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }


你可能感兴趣的:(centos,nginx)