本地主机上的rails子域 [英] rails subdomain on localhost
问题描述
我想在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
只是运行
rails s -p 3000 -b lvh.me
无需触摸/etc/hosts
文件.
默认情况下,如果没有Internet连接,您将无法浏览链接lvh.me:3000
,解决方案是将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屋!