Project Task: Opening Server Ports for Your Web Server
Learn to configure your firewall to safely open HTTP/HTTPS ports. Secure your web server project by managing incoming traffic with UFW on Linux.

Previously in this course, we explored network ports and services to identify which applications are listening on your machine. Now that you know how to map processes to ports, this lesson adds the critical layer of firewall management, allowing you to expose your web server to the internet while maintaining strict security.
Understanding the Firewall First Principles
A firewall acts as a gatekeeper between your Linux server and the outside world. By default, most secure server distributions (like Ubuntu) ship with a "deny-all" policy for incoming connections. This is excellent for security—it means your web server might be running, but no one can reach it.
To change this, we use ufw (Uncomplicated Firewall). It provides a user-friendly interface to manage the underlying iptables rules. Instead of crafting complex packet-filtering rules, you simply tell the firewall which services or ports you want to permit.
Managing Your Firewall with UFW
Before we open any doors, we need to ensure the firewall is actually active. If you are following the Project Kickoff and Project Task: Creating Initial Configs milestones, you are likely working on a clean instance.
1. Checking Status
First, check if your firewall is active:
Bashsudo ufw status
If it returns inactive, you should enable it. Warning: If you are connected via SSH, ensure you allow SSH connections before enabling the firewall, or you will lock yourself out of the server.
Bashsudo ufw allow ssh sudo ufw enable
2. Opening HTTP and HTTPS Ports
For a web server, we need to allow traffic on standard ports:
- Port 80: Used for unencrypted HTTP traffic.
- Port 443: Used for encrypted HTTPS traffic.
Run these commands to permit the traffic:
Bashsudo ufw allow 80/tcp sudo ufw allow 443/tcp
Alternatively, if you have a web server like Nginx installed, you can allow it by name, which automatically opens the necessary ports:
Bashsudo ufw allow 'Nginx Full'
3. Verifying Changes
After applying the rules, verify that the ports are open and the firewall is enforcing them:
Bashsudo ufw status verbose
You should see output indicating 80/tcp and 443/tcp are set to ALLOW from Anywhere.
Hands-on Exercise
Now, it's your turn to configure the project environment. Perform the following steps:
- List your current firewall rules using
sudo ufw status numbered. - Add a rule to allow incoming traffic on port 80.
- Delete that rule by its number (e.g.,
sudo ufw delete [number]). - Re-add the rule, but this time use the "Nginx Full" profile if you have it installed.
- Attempt to
curlyour local IP address to verify the connection is no longer being dropped (note: this requires a web server process to be running).
Common Pitfalls
- Locking Yourself Out: Always run
sudo ufw allow ssh(orsudo ufw allow 22/tcp) before enabling the firewall for the first time. - Ignoring IPv6: By default, UFW applies rules to both IPv4 and IPv6. If you find your server is still unreachable, check
/etc/default/ufwto ensureIPV6=yes. - Over-permissioning: Avoid using
sudo ufw allow 1:65535/tcp. Only open the specific ports your application actually needs. Every open port is a potential attack vector.
Frequently Asked Questions
Q: Does opening a port automatically start the web server? A: No. The firewall only allows traffic to reach the server. You still need an application (like Nginx or Apache) listening on that port to handle the request.
Q: What if I make a mistake in my rules?
A: You can always use sudo ufw delete allow [port]/tcp to remove a specific rule, or sudo ufw reset to wipe all rules and start over.
Q: Is UFW enough to secure my server? A: It's a great start, but it's only one layer. You should also look into Nginx security headers and automate your SSL certificates to ensure end-to-end security.
Recap
In this lesson, we secured our web server by configuring the firewall. We learned how to check the status of ufw, open specific ports for web traffic, and verify our changes. By managing these rules, we've taken a significant step in our project toward a production-ready setup.
Up next: We will discuss Log File Rotation, ensuring your server doesn't run out of disk space as your project logs grow.
Work with me

VPS Server Setup, Deployment & Hardening
Get your app live on a fast, secure server — properly configured, hardened, and deployment-ready. No more wrestling with the command line.

Next.js Full-Stack Web App Development
A fast, SEO-ready full-stack web app built with Next.js 16 — from idea to deployed product, by an engineer who ships to production.

