Rails 4 Subdomain on production (Nginx + Passenger) - ruby-on-rails

I've setup 1 apps for ex, example.com with devise auth on it. So when user signup, it will automatically create the subdomain for that user, for ex: user1.example.com where it will showing user profile, (as i follow here: https://railsapps.github.io/tutorial-rails-subdomains.html)
In my development env which is i use pow, everything work fine but not for production env. I can't access my user subdomain. It said something like "because the DNS lookup failed".
So my question, do I miss something to configure from the nginx site? or maybe from the dns?
Thanks in advance

For nginx essentially server_name *.example.org and same in dns settings for your domain - have the DNS entry as * as an A record.

Related

Heroku Automated Certificate Management not working

I have a domain, example.com. It's running on hobby dynos in Heroku, so I figured I would enable Heroku Automated Certificate Management. I've set up Heroku like so:
=== example Custom Domains
Domain Name DNS Target
─────────────── ─────────────────────────────
example.com example.com.herokudns.com
www.example.com www.example.com.herokudns.com
My DNS settings are:
CNAME Record www example.com.herokudns.com.
URL Redirect Record # https://www.example.com Unmasked
However, neither the apex domain (example.com) or the www domain (www.example.com) work when I access the domain.
Help would be greatly appreciated.

Create a subdomain on Namecheap for a Heroku Rails app

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

Two Rails apps deployed - How do I change the default App?

I've followed Ryan Bate's guide to deploy two completely different rails apps one one VPS (cost saving, using it for development of small home projects). Link to railscast: http://railscasts.com/episodes/335-deploying-to-a-vps
My issue is: the default application is the one I deployed first, so when I visit the IP address, that is the app which is displayed. How do I configure the server to
Use a subdomain (not sure this is possible using just an IP address)
Change the default app
Had a play around in nginx.conf and read this stack q: NGinx Default public www location?
I can't seem to work it out! Thanks in advance.
I think I understand what you want to do. Your default app term confuses me. Let's throw that out and just say you want to deploy two different rails apps to different domains-- sub or TLD, it doesn't matter. Also, I think you are wanting to deploy them to the same VPS server. Ryan's screencast doesn't include how to do this.
What you are probably looking for is how to host multiple sites (and rails apps) with nginx. Like Ryan's screencast, there are many steps involved to get everything working. I recommend you first focus on domain setup (DNS), then nginx setup. Leaving serving your rails app with unicorn for last.
First
Setup your domain and subdomain to point to the VPS. One way is to create DNS A records point to your VPS IP.
Second
Configure nginx to serve both sites. To get you started in the right direction I recommend you read this: multiple websites on nginx & sites-available. It sounds like you already have nginx serving your app on your domain. So steps might be like:
$ cd /etc/nginx/sites-available/
$ cp default subdomain.example.com
Edit subdomain.example.com accordingly. See nginx docs for details. Also, make sure /sites-available/default and /sites-available/subdomain.example.com are not using _ as server_name directive. Set them to their respective domain names. Also, for now point the root to somewhere that will serve an index.html file (ie. leave rails out of it for now)
$ cd /etc/nginx/sites-enabled/
$ ln -s ../sites-available/eden.jrutherford.com .
$ service nginx restart
If all is well by this point you should be able to visit both domains in a browser and have nginx serve content.
Third
Configure a new unicorn for your subdomain. I'm sorry I don't have specific tips for this step . Follow Ryan's tutorial, search google, unicorn website.
Good Luck.

How to add domains to rails app in heroku

I deployed my app to heroku and I added my godaddy domain to heroku with:
heroku domains:add www.domain.com
heroku domains:add domain.com
But when I type domain.com sometimes it doesnt work and it redirects me to godaddy. Only www.domain.com works fine. Is there anything I am missing in configuration?
This is my DNS records setting
Host
# 68.178.232.100
# 75.101.145.87
# 75.101.163.44
# 174.129.212.2
C-NAME(Alias)
www proxy.heroku.com
From what you've described your Heroku setup is fine. You need to make sure your GoDaddy DNS records are correctly pointing to Heroku, and specifically that your # record is set correctly so the root domain is handled by Heroku.
Update:
The Heroku IPs are:
75.101.163.44
75.101.145.87
174.129.212.2
68.178.232.100 is GoDaddy. Delete that record and you should be ok.
Check your DNS settings. If your DNS is set up properly you may just need to wait for it to propagate out to other nameservers, which can take up to a week. In all likelihood it will only take a day or two.

rails subdomain

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.

Resources