rails subdomain on localhost
After saving /etc/hosts
file, run your rails app like this
rails s -p 3000 -b daycare.no
In a browser
http://daycare.no:3000
Personally, I use lvh.me:3000
just running
rails s -p 3000 -b lvh.me
no need to touch /etc/hosts
file.
By default, you can't browse the link lvh.me:3000
without internet connection, solution is to add 127.0.0.1 lvh.me
into host file.
# /etc/hosts file
127.0.0.1 localhost
127.0.0.1 lvh.me #make sure lvh.me is after localhost otherwise will not work
But, Its little annoying to run this each time when restarting a server.
Set your custom command:
sudo nano .bash_profile
# OR
sudo nano .bashrc
# OR
sudo nano .profile
And ADD these lines to there:
alias lvh='rails s -p 3000 -b lvh.me'
alias lvh_production='RAILS_ENV=production rails s -p 3000 -b lvh.me' #production
Do not forget restart your terminal tab, close and open new tab OR run this command on the same tab . ~/.bash_profile
depends what you have used on top.
Alternate solution is POW (LINK) server can give you custom domain smth like daycare.dev
.
I use www.vcap.me:3000
There is no need to do extra configuration before rails 6.
with rails 6, you need to add www.vcap.me
to environment configuration:
config.hosts << 'www.vcap.me'
You can use it like this:
www.vcap.me:3000
subdomain1.vcap.me:3000
subdomain2.vcap.me:3000
..