Home  >  Q&A  >  body text

nginx - redirect fails after two reverse proxies

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.

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?

怪我咯怪我咯2712 days ago1157

reply all(2)I'll reply

  • ringa_lee

    ringa_lee2017-05-16 17:26:31

    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.

    reply
    0
  • ringa_lee

    ringa_lee2017-05-16 17:26:31

    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.

    reply
    0
  • Cancelreply