Knowledgebase

Find frequently asked questions and setup guides by searching or by browsing the categories.

What Port 80 Is Used For

Port 80 is the standard TCP port for HTTP. An address that starts with http:// and has no port number goes to port 80, and Nginx, Apache, and most other web servers listen on it right after installation. Nothing sent over port 80 is encrypted, so current sites use it for two jobs only: redirecting visitors to HTTPS on port 443, and answering certificate validation requests.

Why Port 80 Stays Open on an HTTPS Site

  • Redirects: people type example.com without https://, and old links point to http:// addresses. The server on port 80 answers with a permanent redirect to the HTTPS address; without it, those visitors get a timeout. See how to redirect HTTP to HTTPS in Nginx.
  • Let's Encrypt HTTP-01 validation: to issue or renew a certificate, Let's Encrypt fetches a token from a path under /.well-known/acme-challenge/ over port 80. It does not publish the addresses it validates from, so the port must be reachable from anywhere. If it is closed, renewals fail; see Certbot renew.

The DNS-01 method proves control through a DNS record instead and does not need port 80. It is also the method for wildcard certificates.

See What Listens on Port 80

sudo ss -ltnp 'sport = :80'

The process column names the program. One line for 0.0.0.0:80 and one for [::]:80 is normal: the IPv4 and IPv6 listeners of the same web server.

Open Port 80

When you change firewall rules over SSH, allow SSH first and keep your session open until a login from a second terminal works. Then, on Ubuntu and Debian with UFW:

sudo ufw allow 22/tcp
sudo ufw allow 80/tcp
sudo ufw status

On AlmaLinux and Rocky Linux with firewalld:

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload

Test from another machine, against your own server:

curl -I http://example.com/

On an HTTPS site, a 301 with a Location header pointing to the https:// address is the expected answer.

Address Already in Use

If Nginx or Apache will not start and its log says the address is already in use on port 80, another program holds the port. Find it with the ss command above. The usual cases:

  • Two web servers: Apache and Nginx are both installed and enabled. Stop and disable the one you do not use, or move it to another port behind the other.
  • A container: a Docker container published with -p 80:80; docker ps shows it.
  • A leftover process: an old process survived a failed restart. Stop it through systemctl, or with a normal kill, not kill -9 as a first step; see how to kill a process in Linux.
  • A standalone certificate run: Certbot in standalone mode binds port 80 while it validates.

Ports Below 1024 Need Root

On Linux, binding to a port below 1024 requires root or the CAP_NET_BIND_SERVICE capability. Nginx and Apache start as root, open port 80, and run their workers as an unprivileged user. Your own application, started as a normal user, cannot bind port 80 and fails with a permission error. Two better options than running it as root:

  • A reverse proxy in front: run the application on a high port such as 3000 on 127.0.0.1, and let Nginx forward ports 80 and 443 to it; see Nginx reverse proxy.
  • The capability in systemd: give that one service the right to bind low ports in its unit file.
[Service]
User=deploy
AmbientCapabilities=CAP_NET_BIND_SERVICE

Run sudo systemctl daemon-reload and restart the service after editing the unit.

Can You Close Port 80?

You can, if every certificate uses DNS-01 or TLS-ALPN-01 validation and you accept that typed http:// addresses fail for first-time visitors. HSTS sends returning visitors' browsers straight to HTTPS, but it does not help someone who has never visited. For most public sites, keeping port 80 open with nothing but a redirect is the better choice.

Was this answer helpful?
Loading...