How to set up a subdomain on Rails localhost
I recently worked on a client project that required setting up a subdomain for each of the client’s customers. For example, they wanted to use
company1.everclimb.co for Company 1 and
company2.everclimb.co for Company 2. Though the app was essentially the same for both
Company 1 and Company 2 there were a few things that changed based upon the subdomain, such as displaying the appropriate company’s logo in the nav bar. I managed to test this locally by editing my hosts file.
You can find your hosts file here:
/private/etc/hosts Because the file is locked, I had to find the File using Finder, move it to the desktop, edit it, save it, and then move it back to
Finder --> Go --> Go to folder --> /private/etc/hosts
Move the file to your Desktop and open it using your text editor. You can add something like:
Save the file and move it back into
/private/etc. Navigate to your rails app and run the server
Assuming you’re running on the default port (3000), you should now be able to access the subdomain at
Drop your email in the box below to subscribe to my newsletter. Once per week you'll get Ruby/Rails tips, guides, job postings, and general thoughts from the web developer trenches.