I need to pass requests to different localhost ports based on server names using nginx.
Developers already have /etc/hosts files that look like this:
127.0.0.1 site1.local
127.0.0.1 site2.local
127.0.0.1 site3.local
# etc...
To serve these sites locally, developers also have a single Apache instance running with a vhost for each site.
We are replacing the single Apache instance with an instance of nginx for each site. To prevent port collisions, the sites have increasing port numers:
localhost:8001localhost:8002localhost:8003- etc
Accessing these sites via localhost:port works fine.
However, we still need to be able to access the sites using site1.local, site2.local, and so on.
I added a new instance of nginx running on port 80 to catch all requests to the site1/2/3.local-named addresses. My desire is for this instance of nginx to pass requests through to the appropriate host based on the server name:
site1.localpasses requests tolocalhost:8001site2.localpasses requests tolocalhost:8002site3.localpasses requests tolocalhost:8003- etc
How can I achieve this in the instance of nginx listening to port 80?