简体   繁体   中英

Subdomains working locally in Rails 4, but not in production (using Heroku and Godaddy)

My rails app uses subdomains to handle requests from different user roles. The app has two user roles, Role1 and Role2. I've been using vcap.me:3000 to test this locally. For example: the request "role1.vcap.me:3000" is processed differently than "role2.vcap.me:3000" because I want Role1 users to see a page that's different to that of Role2 users. The above mentioned works perfectly locally.

My problem is that in production, this is not working: I purchased a domain from GoDaddy (example: domain.com) and I'm deploying to Heroku (example: myapp.herokuapp.com)

I was able to point www.domain.com to myapp.herokuapp.com in GoDaddy by adding a CNAME record that points 'www' to myapp.herokuapp.com. So if I send a request to www.domain.com, I'm directed to my app. However, I have not been able to make the subdomains work. Example: this request role1.domain.com does not direct me to my app.

I followed Heroku's docs on Custom Domain Names for Apps and I tried to find answers in stackoverflow and other sites (links below) that would help me figure out my problem but I couldn't get any of their solutions to work.

https://stackoverflow.com/questions/33086225/heroku-godaddy-ssl-wildcard-setup

Rails, Heroku and Subdomains. Is my special case scenario feasible?

https://forum.upcase.com/t/subdomain-not-working-in-heroku-and-namecheap/5096

Some posts are suggesting that I need to use something like DNSimple (which I never used before). Do I need to use a service like DNSimple? How should I set things up in that case? Or, can I set things up properly just with GoDaddy? What should I do in that case?

Any guidance would be greatly appreciated since I have little experience with DNS. Thanks in advance!

I was able to solve my problem! I didn't have to use a service like DNSimple and could make it work just through GoDaddy. I added a CNAME record *.domain.com that points to myapp.herokuapp.com and added the domain *.domain.com in heroku by doing: heroku domains:add *.domain.com

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM