在启动服务器运行之前,应该配置应用程序主机以便运行应用程序,因为此应用程序支持多个用户的子域,转到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取决于你在顶部使用的内容.