I have a node app which uses vhost to manage subdomains. So, on my localhost I have:
main.localhost
admin.localhost
api.localhost
In production I have:
main.example.com
admin.example.com
api.example.com
I have a staging system on Heroku too.
so what I want to be able to do is:
main.example.herokuapp.com
admin.example.herokuapp.com
api.example.herokuapp.com
That doesn't seem to work. Is there a way of achieving it, or do I need to create a separate domain and point my nameservers there?
Sure this is possible. But you'll need to do this via your main domain, since it appears Heroku doesn't support wildcard subdomains on the herokuapp.com domain. (How to create a subsubdomain for an app on heroku: (e.g. sub.myapp.herokuapp.com))
First, set a CNAME record for *.staging.example.com to point to example.herokuapp.com
Then tell Heroku to route your domain properly:
$ heroku domains:add *.staging.example.com
Related
I want to configure a subdomain on my main website. For example, www.something.com and something.com redirect to the same main website.
I want to add hi.something.com and for this, I used on my nodejs application vhost.
var vhost = require('vhost');
app.use(vhost('hi.something.com', require('./routes/hiIndex')));
//In (./routes/hiIndex) theres just an app.get telling it which page to render when it reaches this URL
When testing it locally, it works, but once I deploy my application to heroku and try to access hi.something.com it doesnt work, it redirect me to the main website, meaning something.com
Do I need to add some extra configuration, perhaps on the DNS settings for google domains or on Heroku?
If so, do I just point it to something.com ??
I have worked with redirect to other websites in form of subdomains but this is my first time trying to make it work from my own application.
You might have a subdomain catch-all redirect which prevents vhost in Node.js from picking up the subdomain. Try adding an A type record in your DNS settings that points to your Herokus server.
I am creating my first MEAN2 app, but I stuck in mid. My site required one front-end (mysite.com) and one back-end(admin.mysite.com) to manage content. In future I would like to have a unique URL (*.mysite.com) for all the uses who will register at my site, for which there would not be a any directory in real. How could I acchieve it in a best way. To be more clear my requirement is -
mysite.com (original site)
admin.mysite.com (a sub-domain to be managed from same server.js file)
*.mysite.com (based on request host)
Note: I have created site using angular-cli are my structure is like below
-mysite(angular 4 app)
-admin(another angular 4 app)
-server.js
This problem is not specific to node.js. However, in order to setup a domain successfully for your web app, you'll need 2 things:
Web Server
This will manage for you virtual hostnames etc. I would advise you to look at setting up nginx as a reverse proxy in front of your node app.
Domain provider
This will actually allow you to publicly use the domain *.mysite.com. Then you will have to setup a DNS Record, generally an A record, to point at your server IP Address.
This is very high level :) but should be enough to get you started.
EDIT
If you want to test locally just setup nginx with a test server name to proxy_pass to your local nodejs app (i.e. http://localhost:3000) and create a host entry in your hosts file for that hostname.
I'm trying to find a current, up to date answer for setting up naked domain with Godaddy and Heroku SSL. My goal is for all pages to land on a secure page at https://www.example.com
https://www.example.com does go to a secure page.
example.com goes to an insecure page.
https://example.com does not work.
My current set up is as follows:
In heroku settings:
Domain Name | DNS Target
example.com | example.com.herokudns.com
www.example.com | www.my-domain.herokudns.com
Go Daddy Settings:
CNAME | www | www.example.com.herokudns.com
Forwarding settings:
Forward to: https:// | www.example.com
Yeah, it's a pretty stupid issue that some of the big DNS manager providers out there still have. The way to solve it is to have a server with an SSL certificate installed, and then point your naked domain to that static IP. The server then will redirect to the "www" version of your domain, which is now served under SSL by Heroku. Tedious.
If you don't want to do all that, just use https://www.nakedssl.com, which does exactly that – but automated (and for free for one domain).
Disclaimer: I'm part of the team that created NakedSSL, but I hope you take this as help and not as self-promotion. As explained above, the problem is as easy as tedious to solve, and I think NakedSSL is a pretty straight forward workaround.
Root domains on Heroku require the use of ALIAS ANAME or FLATTENING records.
Unfortunately, a number of popular DNS hosts such as GoDaddy, Bluehost, Google Domains, OVH, Hostinger and others do not support these types of records. Many of these Providers will tell you there is no such thing as ALIAS, ANAME or FLATTENING Records and many of these providers will tell you to set an A Record instead, however;
A Records do not work with Heroku for routing
A Records require static IP Addresses and static IP Addresses do not work with Heroku for routing, because Heroku (and many other cloud platforms) use dynamic IP's.
Instead, you can either:
Not use a naked domain and just use your www sub domain
Redirect/ Forward your HTTP root domain to your www sub domain. This won't work for your HTTPS root domain though
Use an Alternate DNS Provider. Heroku recommends the following: https://help.heroku.com/NH44MODG/my-root-domain-isn-t-working-what-s-wrong
Solved it.
Best way to get SSL set up is to use this package which automatically makes every page on your app SSL. Fantastic package. https://www.npmjs.com/package/force-ssl-heroku
Getting the naked domain set up with Godaddy easily: Set forwarding to your domain: https://www.my-domain.com. This will redirect non www to the correct place. :)
I believe naked subdomain or wildcards are not supported by heroku automated certs because of the let's encryption restrictions. So you need to set up a subdomain everytime you want to use Heroku's automatic certs.
ALSO VERY IMPORTANT! Don't forget to remove or edit any unsercured links to external assets. Otherwise browsers will jugde the page with those links unsecured as described in the Modzilla support page about mixed content.
I've got a fairly simple app deployed on OpenShift that uses CloudFlare as a DNS provider, since they support CNAME records for the root domain, which our current domain provider does not.
The issue with this setup is somewhere along the line https is not working. I believe this is an OpenShift issue because it's the same kind of issue you get when you've mapped the domain name to your app but haven't added the proper aliases yet - you get a timeout essentially.
We've got two aliases - with www and without. There's no option to specify https or anything with OpenShift aliases from what I can see. There aren't any SSL certificates assigned to these aliases as we do not need or use https - we're on the Free plan.
The main URL to access the site is http://www.jcuri.com - notice this works as expected, however https://www.jcuri.com times out.
Initially we were thinking of using CloudFlare page rules to auto-redirect to a non-https URL however this is locked down behind a paywall which we're hoping to avoid, as we don't need any of the Pro features.
Is there something I'm missing here? It seems that OpenShift is just denying any https connections purely because we don't have certificates assigned to the aliases. I wouldn't even mind if there were certificate errors, at least that would give us a chance to do a redirect on the actual NodeJS application, but we don't even reach that point.
Can anyone offer some advice on this?
Since those domains are not pointed directly at openshift via CNAME, but are seemingly redirected via another service (from what i can tell from the dns) it is hard to say whether it is OpenShift that is causing the https issues. If you do not have a custom ssl certificate installed on openshift, you will just get an invalid certificate error, but since you are using a redirect service, maybe it is possible that the service is checking the certificate first, seeing an error, and then not working?
Since the https page rules you stated above are behind a paywall, this actually makes a lot of sense that they are blocking it, not OpenShift. Godaddy provided a forwarding service that would allow you to point both www and naked domain to openshift correctly using cnames, i have used it before.
I want to host a root domain like "example.com". The Alias addon allows you to host sub domains like "www.example.com".
But how to host the root domain "example.com" on cloudcontrol? Because I want to create a redirect from example.com to www.example.com.
I have already setup an alias from www.example.com to my cloudControl app successfully. But I was not able to setup an alias from example.com to my cloudControl app.
I'm not sure, whether I have understood everything with the Alias addon.
Best regards,
Christian
Since you can't add a CNAME to a root romain you can't link it directly to cloudControl.
The ugly way would be to manually create A-records to the (currently 3) cloudControl-loadbalancer-IPs, but cloudControl changes these (adds/removes loadbalancers) sometimes so you shouldn't do this.
For my apps I usually use the "URL"-record-type many DNS-Providers provide. In the background they use A-records to a seperate webserver that returns a redirect to the www-version.
You can also use a service like DNS Made Easy. They provide a custom type called ANAME, that's basically a CNAME without the CNAME limitations. They take care of updating the IP addresses in the background when necessary.
http://www.dnsmadeeasy.com/technology/aname-records/