Report this

What is the reason for this report?

How can I create a Sub Domain that links to NodeJS application?

Posted on December 23, 2014

I have recently created a NodeJS application and am trying to get a subdomain to point to it. My Digital Ocean DNS is fine and is directing to my server properly. My Apache virtual host is allowing the connection, however it sends back my default document root, not the data that is being served on the specified port. I fear I may be doing it wrong. Could someone provide me with steps on how to make Apache point to a port on my server?

Thanks.



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

I’m not sure exactly how you went about creating and deploying your app, but take a look at the post I just wrote here: http://markrabey.com/blog/2015/02/08/express-site-with-digital-ocean-and-dokku/ - You may be able to abstract some of the deployment steps to help you out.

A standard A or CNAME record can only direct a subdomain at a name or IP address but cannot specify a port. SRV records will allow you to specify a port but may not be supported in all instances. The best course of action to host a node.js application on a subdomain would be to set it up on a droplet with it’s own IP and point your subdomain to that.

Another option would be configuring Apache to reverse proxy requests to NodeJS. Create a VirtualHost that looks like this:

<VirtualHost *:80>
    ServerName node.yourdomain.com

    <Location "/">
        ProxyPreserveHost On
        ProxyPass http://localhost:3000/
        ProxyPassReverse http://localhost:3000/
    </Location>
</VirtualHost>

Replace 3000 with the port your nodejs app is listening on and and node.yourdomain.com with the actual domain name you want to serve your nodejs app on.

Then, restart Apache:

sudo service apache2 restart

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.