How to do a redirect from one server to another server within the same domain?

Hello! Planned move to another server. Made all the settings, moved all the sites. You now need to update DNS records and wait for all traffic going to the new server, then the old can be turned off. However, the question arose, is it possible using nginx to immediately redirect users to a new server and if so, how? Ie has received a request on the old server, and nginx was redirecting the user to a new on the same page. That you need to add config for this? Just ask to help to understand how correct this decision, understand that there will be delays, but how critical will this be? The old VPS is located in the data center of Amsterdam, in new Moscow.
July 8th 19 at 16:05
3 answers
July 8th 19 at 16:07
Solution
Stupid.
Migrate sites, rewrite the DNS.
As soon as you are picked up, new users will go to the new server.
Then wait 3 days to reset the DNS cache and you can close the old one.
If you are using the database on the old server need also prescribe an appeal to the new database.
Instead of the usual localhost server, write the IP of the new server, and merge the base.
Thus you have both servers are using the same (new) database.
On the new server should also allow remote connection.
Why do some nginx redirects still?
Let's say a user visits the site, finds an old server that registers and leaves a comment. After three days all traffic goes to the new server, but the account that registered user and a comment that he added on the new server is missing. The difficulty is that someone's DNS will be updated sooner, someone later. Accordingly, someone will comment on the new server, someone on the old. On different servers will have different information in the database. - santina90 commented on July 8th 19 at 16:10
: Well, transfer the website and make from your old remote access to the database to all users and comments immediately fell on the new server. He you have available already. - caleb_Stehr commented on July 8th 19 at 16:13
Instead of connecting to database localhost, as is usually done. Write xxx.xxx.xxx.xxx the new IP of the database server and the new server should allow remote connecting. - caleb_Stehr commented on July 8th 19 at 16:16
: Thank you for the tip, never even thought of. However, open access to the database from the outside is it safe? And could you explain why the solution with redirecting stupidity? What to do in case of changed not only the base but also files. For example, downloading pictures, files, etc. - santina90 commented on July 8th 19 at 16:19
: You will allow access only temporarily. You can restrict the IP to which is available only on the IP of the old server. Well, just don't need redirect here. It is possible to be perverted, write a script that will sync the data via FTP, but it is frankly perverse. I am sure that it is sufficient to drain then the desired image after the full transition. - caleb_Stehr commented on July 8th 19 at 16:22
: Thanks! - santina90 commented on July 8th 19 at 16:25
July 8th 19 at 16:09
Over the last couple of months, you are already the third here with this question. There are plenty of methods how to do it.
But I'm not going to tell you - use the search, everything is well explained in those answers.
Sorry, I could not find the answer to your question. Over the last few months are only answers about redirects from one domain to another. You could tell what methods are there, I would read more about them read? - santina90 commented on July 8th 19 at 16:12
: There were questions specifically about the relocation of the site to another hosting. - caleb_Stehr commented on July 8th 19 at 16:15
July 8th 19 at 16:11
Why?
Or you have changed the host address?
If the hostname has not changed, then only rewrite the ip - Nicky in the area and all. Traffic will go to the new address.
Moving from one VPS to another. The fact that DNS is not immediately updated for all users, there is a possibility that some of the traffic will go on old and some on new. If the site is dynamic, register, and download their files, it is not very good. Above already advised on the old server to make a remote connection to the database the new server. - santina90 commented on July 8th 19 at 16:14

Find more questions by tags Nginx