I am developing a web app that will have two parts running on two separate domains (RoR at mydomain.com and another server at sub.mydomain.com). When developing locally, I can run the apps on localhost:port1 and localhost:port2.
In order to test, it’d be convenient to modify my /etc/hosts file to work as such:
mydomain.com -> localhost:port1
sub.mydomain.com -> localhost:port2
Is there a way to do this? What do people suggest doing to develop both at the same time?
The hosts file is completely unaware of TCP ports.
It is for name to layer 3 resolution only.
The solution posted by mfussenegger is interesting, but I think the easier question to ask is this:
Why is it necessary to run these on separate ports?
Using any web server that supports HTTP 1.0, you can simply define the host header for each site to be the domain name of that site, and the requests will be routed to the appropriate site.
Your hosts file would have both entries just pointing to localhost.
Link to apache documentation on how to configure this:
http://httpd.apache.org/docs/2.2/vhosts/examples.html