Run a Flask server on port 80

David Y.

The Problem

How do I get Flask to run on port 80?

The Solution

Most common and important network services run on TCP ports between 1 and 1023. This includes web servers, SSH services, and fileshares such as Windows SMB and FTP. For this reason, these are considered privileged ports, and can only be used by processes running as the root user. Therefore, the simplest way to run a Flask server on port 80 is to run it as root, by either using sudo or logging in as root.

sudo python myflask_app.py

However, this can have security implications. In the event that our Flask application contains vulnerabilities that could allow an attacker to access our system, they will be able to do so as root, immediately giving them full control of our system.

A safer and more performant solution is to run Flask on a high port number on the local loopback address and use a web proxy such as NGINX or Apache to proxy requests from port 80 to that local port number. The Flask documentation provides instructions for doing this in the Deploying to Production section:

Loved by over 4 million developers and more than 90,000 organizations worldwide, Sentry provides code-level observability to many of the world’s best-known companies like Disney, Peloton, Cloudflare, Eventbrite, Slack, Supercell, and Rockstar Games. Each month we process billions of exceptions from the most popular products on the internet.

Share on Twitter
Bookmark this page
Ask a questionJoin the discussion

Related Answers

A better experience for your users. An easier life for your developers.

    TwitterGitHubDribbbleLinkedinDiscord
© 2024 • Sentry is a registered Trademark
of Functional Software, Inc.