ruby-on-rails – 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取决于你在顶部使用的内容.

替代解决方案是POW(LINK)服务器可以给你自定义域smth像daycare.dev.

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...