问题原文
原帖链接 · sa289 · CC BY-SA 3.0
In moving a website with a dedicated IP from one server to another, to minimize downtime due to DNS propagation delays, there's the approach of using IP forwarding so that all traffic to the original IP gets forwarded to the new IP.
Is there anything important to know when doing this? Here are the steps I plan to use. Is there anything from a security perspective or otherwise that I'm missing?
echo "1" > /proc/sys/net/ipv4/ip_forward(or set it permanently)iptables -t nat -A PREROUTING -d original.ip.goes.here -p tcp --dport 80 -j DNAT --to-destination new.ip.goes.hereiptables -t nat -A POSTROUTING -p tcp -d new.ip.goes.here --dport 80 -j MASQUERADE- Repeat #2 and #3 but for port
443instead of80if the site has SSL
I understand downtime can be reduced without resorting to this by lowering the TTL of the DNS records far enough in advance of the change, but that's still not quite as good at this at minimizing downtime since supposedly some DNS servers (and perhaps clients) will cache records for longer than the TTL says if it's short.
EDIT:
Part of what got me wondering if there's something I'm missing is the question of why ip_forward isn't always set to 1 and instead defaults to 0 - like is there some security risk or undesired behavior if having it set to 1 in certain situations.
社区高分解答
原帖链接 · user9517 · CC BY-SA 3.0
Part of what got me wondering if there's something I'm missing is the question of why ip_forward isn't always set to 1 and instead defaults to 0 - like is there some security risk or undesired behavior if having it set to 1 in certain situations.
If your system (as with many others) does not need to be a router there is no reason to enable routing.
Regarding port 80. As you already have a webserver listening on example.com it is fairly easy to configure a reverse proxy to the new webserver. There are plenty of examples on Server Fault on how to do this but briefly
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass / http://example.com/
ProxyPassReverse / http://example.com/
ServerName example.com
</VirtualHost>
You can do exactly the same for https on port 443
<VirtualHost *:443>
ProxyPreserveHost On
ProxyPass / https://example.com/
ProxyPassReverse / https://example.com/
ServerName example.com
</VirtualHost>
The only other thing you need to do is configure a local DNS resolver with an entry for example.com so that it is picked up in preference to the global DNS. Something like dnsmasq should do this easily.
In your particular case you an prepare your new vhosts for example.com ahead of time, install dnsmasq and add example.com to your local hosts file. Then when you are ready, enable the dnsmasq service and restart apache and away you go.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
