Sentry Answers>Flask>

Run a Flask server on port 80

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.

Click to Copy
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:

  • SentryFlask Error Monitoring
  • Syntax.fmListen to the Syntax Podcast
  • Community SeriesIdentify, Trace, and Fix Endpoint Regression Issues
  • Syntax.fm logo
    Listen to the Syntax Podcast

    Tasty treats for web developers brought to you by Sentry. Get tips and tricks from Wes Bos and Scott Tolinski.

    SEE EPISODES

Considered “not bad” by 4 million developers and more than 100,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.

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