Nginx-to-Apache proxy that picks the backend server based on the requested URI
The intent of this setup is to demonstrate a method for migrating a website to a new server, or a new content management system, one URI at a time. By taking this approach you do not have to have your entire site ready for transition at the same time. This means getting the new content out sooner and shortening the time between start and finish for each section of your site.
The flow of a request for a web page when using this setup looks like this:
This example setup uses location blocks in Nginx to determine which "upstream" server to route traffic to. Three upstreams have been setup:
- "Old" Apache site with http on port 8081
- "Old" Apache site with https on port 8444
- "New" Apache site with https on 9444 and 10444
The new site uses https for all requests so the port 80 server has location
blocks that issue 301 redirects to the https version of any migrated URI. It
also introduces load balancing on the backend. The load balancing utilizes
the ip_hash
option so that clients are always routed to the same backend
server. This is done since sessions are not synchronized between the Apache
instances.
This demo utilizes Vagrant. It sets up a CentOS 7 virtual machine and exposes it to your local network. To use the demo you should follow these steps:
- Clone the project, cd into its directory, and run
vagrant up
. If you see any failures during the setup all you need to do is runvagrant reload --provision
and it should finish setting things up. - Once the system is up run
vagrant ssh
to connect to the VM. - Run
ifconfig
and look for the IP that looks similar to the one your computer is using. - Open a web browser and go to the IP you just found.
- Click around on the links to see what happens.