Securing Port 3000 on Raspberry Pi: How to Deploy Your Node.js App with HTTPS

When deploying a Node.js application on a Raspberry Pi, it’s common to use port 3000 as the default for development and production environments. However, leaving it open and running over HTTP can expose your app to unnecessary risks. In this post, we’ll walk you through the essential steps to secure port 3000 and ensure your Node.js app runs safely on your Raspberry Pi.

Step 1

Make sure you have already completed this guide to obtain an SSL certificate in your Raspberry Pi.

Step 2

Since we are using Apache. let’s install the following modules by typing:

sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod ssl

Step 3

Now we need to edit the VirtualHost configuration file that was automatically created when we installed the ssl modules. If for some reason you don’t have this file, check if you have any VirtualHost running on port 443 by entering the command apache2ctl -S, otherwise you will have to create one.

sudo nano /etc/apache2/sites-available/000-default-le-ssl.conf

Add this at the bottom of the file::

ProxyPreserveHost On
ProxyRequests Off
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
SSLEngine On
SSLProxyEngine On

My file will look like this:

Save and reboot the Raspberry Pi.

Step 4

Now go to the folder where your app is stored and run:

npm start

All set! You should be using port https for your connection.

No Comments

Post A Comment