DEV Community

Tonny Kirwa
Tonny Kirwa

Posted on

PostgreSQL and Nginx through the firewall using Ports

To allow PostgreSQL and Nginx through the firewall by specifying the ports they use, you can use the ufw (Uncomplicated Firewall) utility on Ubuntu. Here's how you can do it:

Allow PostgreSQL (Postgres) Port:

By default, PostgreSQL uses port 5432. To allow PostgreSQL through the firewall, you can use the following command:

sudo ufw allow 5432/tcp
Enter fullscreen mode Exit fullscreen mode

This command allows incoming TCP traffic on port 5432, which is the default PostgreSQL port.

Allow Nginx Port:

Nginx uses port 80 (HTTP) and/or port 443 (HTTPS) to serve web traffic. You can allow these ports using the following commands:

For HTTP (port 80):

sudo ufw allow 80/tcp
Enter fullscreen mode Exit fullscreen mode

For HTTPS (port 443):

sudo ufw allow 443/tcp
Enter fullscreen mode Exit fullscreen mode

These commands allow incoming TCP traffic on ports 80 and 443, which are the default ports for HTTP and HTTPS traffic served by Nginx.

After running these commands, make sure to check the status of the firewall rules to ensure that they are correctly configured:

sudo ufw status
Enter fullscreen mode Exit fullscreen mode

You should see the rules you've added, and they should be marked as "ALLOW." If everything looks correct, you can reload the firewall to apply the changes:

sudo ufw reload
Enter fullscreen mode Exit fullscreen mode

Your PostgreSQL and Nginx services should now be accessible through their respective ports, and they are allowed through the firewall.

Top comments (0)