1

I am developing a multi tenant app and need to modify my etc/hosts file to test the different URLs tenants might use. Some will use a sub domain like tenant1.mysite.com and others will use entirely their own URL like tenant2.com (to mask the fact it's a whitelabel site and pretend its their own).

In my hosts file I have:

127.0.0.1 mytenantsdomain.com
127.0.0.1 localhost
127.0.0.1 thor.localhost
127.0.0.1 potter.localhost
127.0.0.1 testtenant.com

localhost, thor.localhost, potter.localhost all work as expected when adding :8000 to them. i.e. they connect to the local development server and show expected tenant-specific content. But, mytenantsdomain.com and testtenant.com both give ERR_CONNECTION_REFUSED - I'm guessing its for the lack of the port :8000 tbh.

I have tried a few fixes like flushing the cache with the below but nothing has worked.

sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder     

Anybody know what else I can try to get them all working?

David
  • 141
  • 6

1 Answers1

1

For anyone coming to this later - after a bit more digging (on serverfault.com), the following lessons:

  1. etc/hosts isn't the place for this. It just resolves a text domain name to an IP. It's nothing to do with ports.
  2. The solution was just to add :8000 after the .com - http://mytenantsdomain.com:8000/ resolves to the local dev server.
  3. To make this permanent (i.e. not have to add :8000 to it), port forwarding would be the way to go. So you need a solution something like this: https://serverfault.com/questions/791181/redirecting-traffic-to-a-specific-address-and-port-using-pf-on-macos
David
  • 141
  • 6