Redirecting to a new domain
If a product or company decides to rebrand and rename, then one key part of this is to redirect the old domain to the new one. Even the top names such as Google (who started as BackRub) and eBay (who started as AuctionWeb) have had to go through this process, so it's more common than people realize.
In order to maintain all previous links and functionalities, ensuring all URLs are redirected to the new domain is critical. Thankfully, all that's required is a simple redirect with a rewrite to ensure that the full URL and all arguments are correctly sent to the new domain.
How to do it...
As in the previous recipe, we need to have two distinct server
blocks. Here's how to redirect the old site:
server { listen 80; server_name oldsite.nginxcookbook.com; return 301 http://newsite.nginxcookbook.com$request_uri; } server { listen 80; server_name newsite.nginxcookbook.com; location / { root /usr/share/nginx...