本地主机上的 rails 子域 [英] rails subdomain on localhost

查看:28
本文介绍了本地主机上的 rails 子域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I would like to test subdomains on localhost. I have following instructions: Before starting the server to run the application, the host should be configured so that the application can support subdomains for multiple users. To do that, go to your hosts file by typing sudo nano /etc/hosts in your terminal, then add subdomains at the end of the file as below:

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/

I followed the above instructions. The following error was encountered while trying to retrieve the 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应用

After saving /etc/hosts file, run your rails app like this

rails s -p 3000 -b daycare.no

在浏览器中

 http://daycare.no:3000

就个人而言,我使用 lvh.me:3000 只是在运行

Personally, I use lvh.me:3000 just running

rails s -p 3000 -b lvh.me

无需触摸 /etc/hosts 文件.

默认情况下,没有网络连接无法浏览链接lvh.me:3000,解决方法是在host文件中加入127.0.0.1 lvh.me.

By default, you can't browse the link lvh.me:3000 without internet connection, solution is to add 127.0.0.1 lvh.me into host file.

# /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

但是,每次重新启动服务器时都运行它有点烦人.

But, Its little annoying to run this each time when restarting a server.

设置您的自定义命令:

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 取决于你在上面使用了什么.

Do not forget restart your terminal tab, close and open new tab OR run this command on the same tab . ~/.bash_profile depends what you have used on top.

另一种解决方案是 POW (LINK) 服务器可以为您提供自定义域,例如 daycare.dev.

Alternate solution is POW (LINK) server can give you custom domain smth like daycare.dev.

这篇关于本地主机上的 rails 子域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆