Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to forward any http request from my old server IP to my new IP.

I migrated servers and there are a few domains that have a high TTL and I could not update. Is it possible to take all HTTP requests from one server running centos/whm/php/apache 2+ and forward them to the new ip?

Since I have hundreds of domains I'd prefer a solution that involves running an app on the linux box that will push requests automatically to the new box.


I've tried using IP tables and forwarding all incoming connections using the preroute chain, but it seems like this only works for forwarding to internal IP addresses, and the new IP is external.

share|improve this question
I think you probably forwarded the packets rather than the connections (through NAT). Forwarding the connections should work. – David Schwartz Nov 14 '11 at 3:20
up vote 1 down vote accepted

Basically you need to set up nginx on your old IP. And your should alter its config to make it act as a reverse proxy, something like this:

server {
        listen   80 default;
        server_name  localhost;

        access_log  /var/log/nginx/localhost.access.log;

        location / {
                proxy_pass         http://your_new_ip_here:80/;
                proxy_redirect     off;
                proxy_set_header   Host             $host;
                proxy_set_header   X-Real-IP        $remote_addr;
                proxy_set_header   X-Forwarded-For  $remote_addr;

                client_max_body_size       10m;
                client_body_buffer_size    128k;

                proxy_connect_timeout      90;
                proxy_send_timeout         180;
                proxy_read_timeout         180;

                charset utf-8;
share|improve this answer
Where do I put this? I put it in the config but it said unknown directive server – Jason Nov 14 '11 at 3:21
Starting nginx: nginx: [emerg] unknown directive "server" in /etc/nginx/nginx.conf:13 – Jason Nov 14 '11 at 3:21
All good, worked it out ... had to edit /etc/nginx/conf.d/default.conf. Thanks, this worked perfectly! – Jason Nov 14 '11 at 3:26
This is just an excerpt, the full config should have more lines, let me paste you a full example somewhere – Alex Nov 14 '11 at 3:27
Oh I see. Great! – Alex Nov 14 '11 at 3:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.