If your application is on Node JS, you must be aware of using the port for your application. Node JS need to be an open port on your system.
As if you are developing an application and your application is on a staging platform, Its good to have port after your domain or port. like //localhost:3000. But when your application is going to be live on production. then for user interface or any other requirements, you don’t want to have that port after domain name or IP Address.
Here a small change in your server file can achieve things get done.
Let’s see you are running application on port 3000.
Now upload your application on hosting server. Now you can access your application via IP address. e.g. IP_ADDRESS:3000.
Create the First Virtual Host File
Start by copying the file for the first domain on your terminal (SSH)
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/yourdomain.com.conf
Open the new file in your editor with root privileges:
sudo nano /etc/apache2/sites-available/yourdomain.com.conf
Delete everything in it, and paste the following after changing your domain name.
<VirtualHost *:80> ProxyPreserveHost On ProxyRequests Off ServerName mydomain.com ServerAlias www.mydomain.com ProxyPass / //localhost:3000/ ProxyPassReverse / //localhost:3000/ </VirtualHost>
Now run following command to activate proxy and restart apache.
sudo a2enmod proxy && sudo a2enmod proxy_http && sudo service apache2 restart
Update: If you are doing for a custom subdomain, then you need to point the subdomain to the IP Address.
happy coding 🙂