How to set up a custom domain on Heroku - ruby-on-rails

I've deployed a Rails 3.2 app to Heroku. I would like the app to be accessible from http://myapp.mydomain.com and for routes to be accessible from this url, e.g. http://myapp.mydomain.com/ModelA/1
I've followed the instructions at https://devcenter.heroku.com/articles/custom-domains
When I enter http://myapp.mydomain.com in the bowser addressbar it successfully takes me to the app.
BUT the url is rewritten as myapp.herokuapp.com
I've already added the domain to Heroku heroku domains:add myapp.mydomain.com.
How do I maintain the custom domain throughout my app?

This looks like a DNS config issue. You should check your hosting provider to make sure you have your site set up as a CNAME to proxy.heroku.com, not a redirect or anything else.
(Glad you were able to solve it!)

Related

Rails Heroku Cloudflare Setup - www won't work

I have a rails app that's configured to force SSL:
Rails.application.configure do
config.force_ssl = true
end
It is then deployed to Heroku (free tier), where I configured to add my custom domain.
On Cloudflare, I only have these 2 records:
CNAME example.com example.herokuapp.com
CNAME www example.com
I also set the SSL option to be full.
My understanding is that, when people visit my webiste at www.example.com, they get redirected to the apex (non-www) url.
However, now whenever I visit the www version, it shows me the Heroku's No Such App page.
I have no idea what I did wrong and have tried all sorts of ways I have found online for a whole week. Hope someone can help me out, thanks!
Looking at the response from heroku 'No such App' found, please confirm if www.example.com is added as custom domain under settings?

Should Heroku's HOST_URL var be configured to match the domain name?

Say you have set up a domain (my-domain.com) to be used for an app on Heroku (myapp.herokuapp.com). It seems to be working as intended. However, you notice when you check the heroku config, you get this:
HOST_URL: myapp.herokuapp.com
Should you set the HOST_URL to your domain?
This is for a ruby on rails app.
It appears to be important if you want to use _url for any links. _url will use the HOST_NAME var from the heroku config. Since I needed to use that for links within an email, I changed it with:
heroku config:set HOST_URL="my-domain.com"

Linking Rails App and Wordpress Blog on different hosts

I have setup my Rails app on a VPS and a WordPress blog on GoDaddy. I did this because I don't want to have to install PHP on my VPS. Also, my rails app is using Postgres and while I am aware that WordPress can be setup to use Postgres, I just don't want to go through the hassle.
How do I link the blog and my rails app, such that the blog is located at:
www.mysite.com/blog
Also, when internally navigating on the blog, the base URL should remain www.mysite.com/blog
For example:
www.mysite.com/blog/article1
www.mysite.com/blog/category
And so on....
Assuming that your Rails site runs with an Apache in front, here is something you can put into the VirtualHost part of your Rails site:
<Location /blog>
ProxyPass http://godaddy.com/yourwordpress-site/
</Location>
In Nginx it would look like this
location /blog {
proxy_pass http://godaddy.com/yourwordpress-site;
}
Of course I would recommend, that you add some more options to the proxy setup so that the IP address of the original requester is kept etc. Doing it this way, the Webserver already catches the request and doesn't even bother your Rails app with requests that it doesn't really know about.
to redirect correctly, but not hide the url of the wordpress site
in your rails app's routes.rb
match "/blog" => redirect("http://YOUR_WORDPRESS_BLOG_SITE_URL")
Make sure you didn't forget to add http/https in your redirection url
Another alternative is to use a subdomain (instead of a subfolder), like blog.mysite.com, and then it can be handled using plain and simple dns.

Configuring SSL for an App Heroku HTTPS

Hello I am currently going through the tutorial below to add ssl to my heroku app
https://gist.github.com/shripadk/552554
so for today, I bought a domain name, set the cname to point to my heroku app
Currently my domain name is working.
I am trying to add ssl security feature to my app so secure.domainname.com works
Following the tutorial
heroku addons:add custom_domains:basic
I got an error
add ons not found
I can't find this add on on heroku as well. but I searched this command through stackoverflow and its suppose to exist?
I got the same error with this command
heroku addons:add ssl:hostname
but it also said adds on not found, later I found this same add on heroku but its with a different command.
This is the part that I don't get on the tutorial
After adding the ssl add on
This will add a $20/month (as of the time of this writing) fee to your Heroku bill for SSL.
VI: Setting up your DNS to work with Heroku Hostname SSL
You should recieve an email from heroku within a few minutes of adding the ssl:hostname addon. You need to add a CNAME record to your DNS that points to the AWS host in the email you receive. This should be pretty self explanatory, but if you have any questions, search for 'adding a CNAME record' in Google and you'll see lots of good guides.
Test that 'host secure.yourdomain.com' outputs 'something.amazonaws.com'. If it does, you're all set.
You should now be able to go to 'https://secure.yourdomain.com' and not see any errors or security warnings.
What is going on behind the scenes
When a user visits your site using 'http://secure.yourdomain.com', they're hitting your GoDaddy CNAME record, which points to an 'something.amazonaws.com' address which effectively routes the request to Heroku's grid, and a secure connection gets established from there following the standard SSL handshake process.
I didn't get an email, neither does appname.herokussl.com exist?
Am I suppose to use Zerigo DNS? for anything, its mentioned once in the top of the tutorial but not anywhere else?
From reading the comments, someone got a problem with the end part as well.
Thanks!
I followed this tutorial for both heroku and for my own server setup and when trying to setup on heroku for the first time I did not do it correctly so I will explain some of the important steps when setting up ssl on heroku.
Use OpenSSL to generate a new self-signed certificate ('host.csr') using the host key we just created. This is what you'll be sending to
GoDaddy to model your new SSL after.
At the step above make sure you fill in the information correctly and also make sure your common name matches your ssl certificate name.
2. Combine 'secure.yourdomain.com.crt' and 'host.key':
You will need to combine your ssl keys. If you're using godaddy there are 2 files included name gd_bundle.crt and secure.yourdomain.com. Upon during the tutorial you will generate about 5-6 files in which you will only use 1.
Remove pass phrase from the public key certificate (required by Heroku)
In order for heroku to read your ssl cert you will need to remove all passwords on the certs so make sure the passwords are removed. There will be two files depending on how you have combined them with the extensions .pem and .key (The updated ones not the ones you started with).
You've most likely added the domain and subdomain so now through the command line run
heroku ssl:add ../ssl-cert/public.pem ../ssl-cert/private.key
Remember get the path of the newly updated files. Also when editing the files and copying over keys make sure there are no white spaces in between keys. Let me know if this helps.

how to make url in rails app that is not domain specific

I am making a dynamic URL in my rails app like
http://localhost:3000?#{something}=#{something1}
How do I get rid of the hardcoded domain name (localhost in this case). I want to deploy this app to heroku and heroku will give its own domain name. I don't want to again change my code to suit the domain name that heroku gives.
Is this possible?
Replace localhost:3000 with request.host_with_port
http://api.rubyonrails.org/classes/ActionController/Request.html#M000521

Resources