0

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:8001
  • localhost:8002
  • localhost: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.local passes requests to localhost:8001
  • site2.local passes requests to localhost:8002
  • site3.local passes requests to localhost:8003
  • etc

How can I achieve this in the instance of nginx listening to port 80?

0 Answers0