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

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?


Submit an answer

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!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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

<VirtualHost *:80>

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

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

Then, restart Apache:

sudo service apache2 restart

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: - 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.