local Rails with domain name? [duplicate]

2019-06-18 14:46发布

问题:

Possible Duplicate:
How to specify a web address to a rails application?

I want to boot 2 Rails on my machine. I can do this way:

rails s -p 3000
rails s -p 3001

And access them through localhost:3000 and localhost:3001.

But is there any way to boot them on foo.example.com and bar.example.com? I don't really own the domain name example.com, and I just want my local programs to access them through this fake domain name instead of localhost.

回答1:

If you're on Linux (I'm not sure of this in Mac), edit the file /etc/hosts with sudo, and add two lines:

127.0.1.1      foo.example.com
127.0.1.1      bar.example.com

If you point your browser to any of them, it should work. Then start the servers of your Rails Apps:

rails s 
rails s -p 3001

Finally point your browser to:

foo.example.com:3000
bar.example.com:3001