nginx - redirect fails after two reverse proxies
怪我咯
怪我咯 2017-05-16 17:24:31
0
2
1156

There is a server on the intranet with 3 ports providing Web services. The servers are nginx, apache and serv-u. Now we need to forward three services to the external network.

  • No permission to control the router
  • The network management only uses PortTunnel to forward port 80 to the external network 882

So I wanted to merge it into a port forwarding and use nginx to reversely determine the host.
nginx.conf is as follows:

server {
    listen       80;
    server_name  no1.home s1.abc.com;
    index index.html index.htm index.php;      
    access_log off;
    location / {
        proxy_set_header   X-Real-IP  $remote_addr;
        proxy_set_header   X-HappyHome  XMWZWX;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://10.110.39.2:10;    
    }
}

The three pieces of code replace three items respectively. It is normal after using Host to parse, but once the external network set by the network management is used, problems will occur:

After visiting http://xxx.com:882/folder
It will automatically jump to http://xxx.com:80/folder/

What is the problem? Is nginx.conf configured incorrectly?

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(2)
左手右手慢动作

Okay, I found the answer after looking through the nginx documentation for a long time.
Add a sentence
proxy_redirect "http://10.110.39.2:80" "http://$host:882" ;
to the configuration of the three sites That's it.

左手右手慢动作

The problem cannot be seen in the configuration file posted. So I can only give the following suggestions (in order):

  1. Open access_log and confirm that the request to access http://xxx.com:882 has indeed been processed by the nginx. It is recommended to check the global log rather than the log configured for this virtual server. This can be used to eliminate the problem of requests being processed by other virtual servers due to configuration errors.
  2. If [1] is confirmed, confirm http://10.110.39.2:10 whether the request is received in the same way.
  3. If [2] is also confirmed, then at this time, please debug the application listening 10.110.39.2:10.
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!