Ubuntu Apache add reverse proxy to avoid port number visibility | NodeJS

When we create APIs using nodejs we often enable them to run on particular port number. It is all fine until we move into production environment where we don’t want our port number to visible to our clients while we are making the server request calls using the APIs.

So a solution would be to mask our port number and let apache handle the request and redirect the request to that server internally without revealing the port number. For this we need to edit the apache configuration like following.

Open the file /etc/apache2/sites-enabled/000-default.conf using any editor and add the following lines under or above the directory tag.

<Location /query-api-0.3.1>
ProxyPass http://localhost:3099/query-api-0.3.1
ProxyPassReverse http://localhost:3099/query-api-0.3.1
Order allow,deny
Allow from all

Reverse Proxy exmaple in apache

Then save the file and restart apache and try to run the API request without the port number.