Question

How to unblock port 3001 and 3002

Posted June 28, 2021 77 views
Nginx

I have an app that has 3 different processes port 3000, 3001, 3002. I needed port 3000 to be mapped to port 443 (https) so the users don’t go to port 3000 to access the webpage. But the ports 3001, and 3002 are blocked. My current solution is to do open ports 3001, 3002 the same way as 3000, but that would not work as that will also map those ports to https.

Location block:

location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                proxy_pass http://localhost:3000; #whatever port your app runs on
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_cache_bypass $http_upgrade;
        }
edited by MattIPv4

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.

×
Submit an Answer
1 answer

Hi there @adityachandra,

If you do not have a firewall, in order to open the ports you would need to just start the specific services on those ports. Do you see all ports when running the following command:

netstat -plant | grep 300

If you have a firewall like UFW for example, and if you want to be able to access the ports directly, then you would need to open the ports with the following commands:

ufw allow 3001

In case that you want to add another endpoint for your application like /shop for example, you could add an additional location directive to your server block:

location /shop {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                proxy_pass http://localhost:3001; #whatever port your app runs on
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_cache_bypass $http_upgrade;
        }

If the new services are going to be completely separate websites with separate domain names, then you would need to create a new server block by coping the existing config file from /etc/nginx/sites-available/your_conf and updating the details accordingly. Then you could follow the steps here on how to enable the new server block and restart Nginx:

https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-virtual-hosts-on-ubuntu-16-04

Hope that this helps.
Regards,
Bobby

by Justin Ellingwood
When using the Nginx web server, server blocks (similar to the virtual hosts in Apache) can be used to encapsulate configuration details and host more than one domain off of a single server. In this guide, we'll discuss how to configure server blocks in Nginx on an Ubuntu 16.04 server.