Categories
Uncategorized

Point Domain To Nodejs Applications

Generally when we setup a Nodejs/React application we configure to run it on some ports. But while going live we need to point a domain/subdomain or even SSL to make certain things work like (web push notificaitons).

You can easily do this by setting up Apache on your ubuntu server and then creating virtual hosts (as usual). You can follow this to setup shell script for easily creating virtualhosts.

Once virtual hosts are set then you need to setup reverse proxy and point your subdomains/domains to respective nodejs urls. Here is example of how your /etc/apache2/sites-available/d[omain-name]-le-ssl.conf will look like:

<IfModule mod_ssl.c>
	<VirtualHost *:443>
		ServerAdmin webmaster@localhost
		ServerName SUBDOMAINNAME.COM
		<Location "/">
		 ProxyPreserveHost On
		 ProxyPass http://localhost:4000/
		 ProxyPassReverse http://localhost:4000/
		</Location>
		ErrorLog /var/log/apache2/[SUBDOMAINNAME]-error.log
		LogLevel error
		CustomLog /var/log/apache2/[SUBDOMAINNAME]-access.log combined
		SSLCertificateFile /etc/letsencrypt/live/[SUBDOMAINNAME]/fullchain.pem
		SSLCertificateKeyFile /etc/letsencrypt/live/[SUBDOMAINNAME]/privkey.pem
		Include /etc/letsencrypt/options-ssl-apache.conf
	</VirtualHost>
</IfModule>

* * Replace SUBDOMAINNAME.COM with your subdomain

** Make sure letsencrypt ssl files path is correct

** http://localhost:4000 is your nodejs/reactjs app url.

Leave a Reply

Your email address will not be published. Required fields are marked *