How to Mirror a Website with Nginx

To mirror a website, update the proxy_pass configuration and pass the original domain in the Host header. This is useful when redirecting traffic from an old server to a new one.

Open the server configuration

nano /etc/nginx/sites-available/server_name

Replace location / 

location / {
              # Redirect everything that isn't a real file to index.php
              #try_files $uri /index.php$is_args$args;
              proxy_pass https://000.000.000.000;
              proxy_set_header Host $host;
              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
              proxy_set_header X-Real-IP $remote_addr;
      }

If there is a location ~ \. block, replace it

 location ~ \.(png|jpg|gif|js|css|swf|ico|pdf|svg|mov|fla|zip|rar)$ {
              #expires 1M;
              #access_log off;
              #add_header Cache-Control "public";
              #try_files $uri 404;
              proxy_pass https://000.000.000.000;
              proxy_set_header Host $host;
              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
              proxy_set_header X-Real-IP $remote_addr;
        }

Check that the configuration is valid

nginx -t

Reload Nginx

sudo service nginx restart