nginx proxy all traffic to remote nginx

user676674 picture user676674 · Mar 25, 2011 · Viewed 82.8k times · Source

I have 2 servers,

  1. with IP xx.xx.xx.xx, situated in Germany ... (running frontend: nginx(static content), backend: Apache2)

  2. with IP yy.yy.yy.yy, situated in Italy...

All requests at the moment is sending to server with IP xx.xx.xx.xx, How can I proxy all traffic from xx.xx.xx.xx to yy.yy.yy.yy using nginx ...

          request                           proxy, request
Internet     ->       xx.xx.xx.xx(nginx)         ->             yy.yy.yy.yy(nginx, Apache)
             <-                                  <-
          response                          proxy, response

Thanks ...

Answer

Vladimir Shmidt picture Vladimir Shmidt · Oct 27, 2011

For others. Answer for subject is configure nginx like:

server {
  listen 80;
  server_name mydomain.com;
    location / {
      access_log off;
      proxy_pass http://mydomain.com:8080;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header Host $host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}