I went to this tutorial http://railscasts.com/episodes/221-subdomains-in-rails-3 and trying to implement in http://ngtv2.info
but after I place the code in routes.rb
match '/' => 'projects#show', :constraints => { :subdomain => /.+/ }
and then typed kingpangilinan.ngtv2.info
the browser says that "Server not found", Firefox can't find the server at kingpangilinan.ngtv2.info
Any help is appreciated.
You have to setup your DNS to point to your webserver. Just telling Rails to answer for a specific domain doesn't setup the DNS to do the same.
$ nslookup kingpangilinan.ngtv2.info
** server can't find kingpangilinan.ngtv2.info: NXDOMAIN
Use the interface of your domain provider or ask them directly to setup a wildcard DNS entry.
If you are using Rails 3 you shouldn't be using that Railscast (it's from 2008 anyway). There's a newer version which is specifically targeted for Rails 3: http://railscasts.com/episodes/221-subdomains-in-rails-3
By the way: You should not deploy a yet unfinished app without any protection. Development should happen locally or at least behind a password secured website.
This has got nothing to do with Rails and everything to do with DNS and the way the Internet works.
You must configure the DNS zone for ngtv2.info with a wildcard subdomain entry before you can try setting up Rails to catch these subdomains.
To test subdomain routing out locally, you should try running the app on your computer and browsing to it at http://lvh.me:3000 instead of http://localhost:3000. Then you can also browse to http://anysubdomain.lvh.me:3000 and Rails will catch that it's a subdomain.
If you want to develop on your local machine using the subdomain constraint modify your /etc/hosts by adding
127.0.0.1 SUBDOMAIN.localhost.de
Then rails can infer the subdomain from your request. Make sure you use the URL you specified in the /etc/hosts and not localhost:3000.
Related
Awhile back, lvh.me was broken for me locally when running feature tests for rails. I solved the issue by editing a file locally that ensured lvh.me would point to localhsot:3000 - it was a solution I found after much googling, and now I cannot remember what file it was that I edited or what the solution was.
Enter a new problem: I'm trying to use ngrok to point to my localhost:3000 in order to test Amazon Connect integration, but ngrok consistently redirects to lvh.me instead - which, for my organization, points to our production site and database. Ngrok is pointing to Web Interface http://127.0.0.1:4040 and says it's forwarding to localhost:3000
Why is ngrok redirecting to lvh.me, and how do I fix this?
I'm not sure about the solution but I think file you was edited to ensure lvh.me pointed to localhost:3000 is located at /etc/hosts.
I have a domain name registered on namecheap. Let's say it is mysite.com. I want this domain to be my personal site. I also want to create a subdomain like myapp.mysite.com for a Rails app on Heroku.
I have tried to configure one in the DNS section of the Namecheap dashboard but I'm new with theses things. I'm using a CNAME type, # for host and automatic for TTL.
I have also added myapp.mysite.com as a custom domain in my Heroku dashboard.
Am I doing this right? Please explain it in detail so I can learn more about DNS.
EDIT:
I have changed my subdomain like this:
Type: CNAME
Host: myapp
Value: mysite.om
TTL: Automatic
Since the DNS has updated, I now get a 400 bad request error from Nginx.
Is it because of Heroku? Do I have to add some setting in Heroku?
I have found the solution for my question. So first of all, the correct configuration for the advanced DNS:
Type: CNAME
Host: myapp
Value: myapp.herokuapp.com (without the https protocol)
TTL: Automatic
After that, it takes a moment for the DNS to update the subdomain and make it available. During this time, I needed to add my subdomain to my Heroku configuration. It is possible via the dashboard of via terminal.
I did it via terminal with this command:
heroku domains:add myapp.mysite.com
After some time, it finally worked. However, having a custom domain or subdomain disable the default SSL from Heroku.
I mostly learn via this article:
https://devcenter.heroku.com/articles/custom-domains
The selected answer didn't work for me. But following the docs did.
Open terminal
heroku domains:add www.example.com
host www.example.com
Copy the url that looks like: whispering-willow-5678.herokudns.com
Note It will always be suffixed by .herokudns.com
Add a CNAME Record with the host (www, in my example).
Paste in the url you copied under Value (see screenshot below).
Click the check mark on Namecheap
Profit
Resources
Heroku Docs
Namecheap Docs
i've got some problems with my ruby on rails server.
It is running under localhost:3333 in my debian vm under a windows8 host.
I've installed apache2 and passengermodul for apache to get ruby. And then I've installed rails.
Now I need a subdomain wich calls the ruby on rails server.
for example admin.localhost:3333
Is something like that possible? And when how can I configurate it?
You can use the lvh.me domain. That domain has a DNS entry that will redirect to localhost. This also works for subdomains, so you can visit admin.lvh.me:3000 and it will redirect to localhost:3000 while still having the subdomain available in the Rails request.
The advantage is that you don't have to edit your localhost file.
Add custom hosts with subdomains to the hosts file, follow these steps
In your terminal, open hosts file
cd /etc
sudo nano hosts
Add the host as mentioned in the following lines to the hosts file, you can add as many as you want
127.0.0.1 admin.localhost
127.0.0.1 subdomain.localhost
Save the file, CTRL + X then press Y
Done.
To run with a custom port, specify the port number while starting the server,
rails s -p 3333
Now you can run your application with, admin.localhost:3333
Hope this helps!
I'm trying to install Locomotive CMS on a virtual rackspace server using their multisite option. I get as far as running the installation and choosing my first subdomain with no problems. But once I create this, the subdomain address gives a 404 error and the root domain give me a 'No site!' error!
I've set up the records in /etc/hosts and am using Unicorn. Am I missing something obvious?
Thanks
Try using pow (along with the powify gem) to setup your hosts. Works a breeze!
I've got the following problem. I want to explicitly tell rails the port it is running on, so that the _url helper will use that port instead of the autodiscovered port.
The underlying problem is, that I have thin serving my rails app and apache serving static content. This works fine as long as the website is accessed on port 80 (apache) but not when accessed on the port thin is running on. (Which is the port that get's auto discovered.)
Rails is supposed to create relative links, which do not include the fully qualified domain name, see example here, I quote :
link_to "Profile", profile_path(#profile)
# => Profile;
the *_url shortcuts, on the other hand, are using the full path, which is bad when you're behind a reverse proxy (that's apache in your case).
Have you tried using only *_path for links, and *_url for redirects, as, in the case of a redirect, apache should rewrite the url to match its port (assuming you're using the ProxyPass and ProxyPassReverse directives at Apache level) ?
If you use url_for, you can force it to be relative by setting the :only_path to true.
If your apache configuration is not based on ProxyPass, could you please copy/paste the interesting part so I can fix this answer ?
Thanks in advance.
Because Ruby on Rails uses its own server, users visiting your website (and subsequently your Ruby on Rails application) will need to be redirected to the appropriate port.
To change the port of Ruby on Rails server you should start the server with the -p option:
ruby s -p <port-number>