Rails subdomain in localhost

Before starting the server, the application host must be configured to start the application to start the application, since this application supports subdomains for several users. Go to your etc / hosts file and add subdomains as shown below:

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 

This is a requirement, and I do it, but now

  http://daycare.no:3000 

not working and give me an error

 **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.** 
+5
ruby ruby-on-rails
Apr 09 '16 at 18:43
source share
3 answers

After saving the /etc/hosts file, run the rails application as shown

 rails s -p 3000 -b daycare.no 

In browser

  http://daycare.no:3000 

Personally, I use lvh.me:3000 only to run rails s -p 3000 -b lvh.me no need to touch the /etc/hosts .

By default, you cannot view the lvh.me:3000 link without an Internet connection, the solution is to add 127.0.0.1 lvh.me to the 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 a little annoying to run this every time the server restarts.

Ask your command:

 sudo nano .bash_profile # OR sudo nano .bashrc # OR sudo nano .profile 

AND ADD these lines:

 alias lvh='rails s -p 3000 -b lvh.me' alias lvh_production='RAILS_ENV=production rails s -p 3000 -b lvh.me' #production 

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




An alternative solution is to use a POW ( LINK ) server to provide you with a custom smth domain, such as daycare.dev .

+6
Apr 09 '16 at 20:37
source share

Editing your host file is a very dirty way to do such things. The problem here is that some programs do not read this file and are sent directly to DNS for resolution.

A service like xip.io can help. You can use addresses like:

 http://test.127.0.0.1.xip.io/ 

This will always resolve to 127.0.0.1.

There are also things like Puma dev , which come with their own recognizer for the .test domain, so site.test works locally, without having to edit any files.

The advantage of both systems is that you can add arbitrary bits, and this still works: subdomain.test.test and subdomain.127.0.0.1.xip.io are also resolved the same way.

0
Apr 09 '16 at 23:18
source share

I am using www.vcap.me:3000

No need to adjust up to the guides 6 .

with rails 6 you need to add www.vcap.me to your environment configuration:

 config.hosts << 'www.vcap.me' 

You can use it like this:

 www.vcap.me:3000 subdomain1.vcap.me:3000 subdomain2.vcap.me:3000 .. 
0
Aug 16 '19 at 17:28
source share



All Articles