localhost中的rails子域
在启动服务器运行之前,应该配置应用程序主机以便运行应用程序,因为此应用程序支持多个用户的子域,转到etc / hosts文件并添加子域,如下所示:
sudo nano /etc/hosts & add the text below at the end of you hosts file : 127.0.0.1 admin.daycare.no 127.0.0.1 daycare.no 127.0.0.1 worker.daycare.no 127.0.0.1 manager.daycare.no 127.0.0.1 parent.daycare.no
这是要求,我这样做,但现在仍然如此
http://daycare.no:3000
没跑,给我一个错误
**The following error was encountered while trying to retrieve the URL: http://daycare.no:3000/ Unable to determine IP address from host name daycare.no The DNS server returned: Name Error: The domain name does not exist. This means that the cache was not able to resolve the hostname presented in the URL. Check if the address is correct.**
保存/etc/hosts
文件后,像这样运行rails应用程序
rails s -p 3000 -b daycare.no
在浏览器中
http://daycare.no:3000
就个人而言,我使用lvh.me:3000
只运行rails s -p 3000 -b lvh.me
无需触摸/etc/hosts
文件。
默认情况下,您无法在没有Internet连接的情况下浏览链接lvh.me:3000
,解决方法是将127.0.0.1 lvh.me
添加到主机文件中。
# /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
但是,每次重启服务器时运行它都很烦人。
设置自定义命令:
sudo nano .bash_profile # OR sudo nano .bashrc # OR sudo nano .profile
并将这些行添加到那里:
alias lvh='rails s -p 3000 -b lvh.me' alias lvh_production='RAILS_ENV=production rails s -p 3000 -b lvh.me' #production
不要忘记重新启动终端选项卡,关闭并打开新选项卡或在同一选项卡上运行此命令. ~/.bash_profile
. ~/.bash_profile
取决于你在顶部使用的内容。
替代解决方案是POW( LINK )服务器可以为您提供类似daycare.dev
自定义域名。
编辑您的hosts文件是一种非常混乱的方式来做这种事情。 这里的问题是某些软件没有读取该文件并直接进入DNS进行解析。
像xip.io这样的服务可以提供帮助。 您可以使用以下地址:
http://test.127.0.0.1.xip.io/
这将始终解析为127.0.0.1。
还有像Pow这样的东西,它们带有自己的.dev
域解析器,因此test.dev
可以在本地工作而无需编辑任何文件。
这两个系统的优点是你可以添加任意位,它仍然有效:subdomain.test.dev和subdomain.127.0.0.1.xip.io也以相同的方式解析。