gpt4 book ai didi

ruby-on-rails - 本地主机上的 rails 子域

转载 作者:数据小太阳 更新时间:2023-10-29 07:15:03 27 4
gpt4 key购买 nike

我想在本地主机上测试子域。我有以下说明:在启动服务器运行应用程序之前,应配置主机,以便应用程序可以支持多个用户的子域。为此,请在终端中键入 sudo nano/etc/hosts 转到您的主机文件,然后在文件末尾添加子域,如下所示:

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

我遵循了上述说明。尝试检索 URL 时遇到以下错误:http://daycare.no:3000/

Unable to determine IP address from hostname 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 文件。

默认情况下,您无法在没有互联网连接的情况下浏览链接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

关于ruby-on-rails - 本地主机上的 rails 子域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36521114/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com