I have a Flask server running through port 5000, and it's fine. I can access it at http://example.com:5000
But is it possible to simply access it at http://example.com? I'm assuming that means I have to change the port from 5000 to 80. But when I try that on Flask, I get this error message when I run it.
Traceback (most recent call last): File "xxxxxx.py", line 31, in <module> app.run(host="0.0.0.0", port=int("80"), debug=True) File "/usr/local/lib/python2.6/dist-packages/flask/app.py", line 772, in run run_simple(host, port, self, **options) File "/usr/local/lib/python2.6/dist-packages/werkzeug/serving.py", line 706, in run_simple test_socket.bind((hostname, port)) File "<string>", line 1, in bind socket.error: [Errno 98] Address already in use
Running lsof -i :80
returns
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME apache2 467 root 3u IPv4 92108840 0t0 TCP *:www (LISTEN) apache2 4413 www-data 3u IPv4 92108840 0t0 TCP *:www (LISTEN) apache2 14346 www-data 3u IPv4 92108840 0t0 TCP *:www (LISTEN) apache2 14570 www-data 3u IPv4 92108840 0t0 TCP *:www (LISTEN) apache2 14571 www-data 3u IPv4 92108840 0t0 TCP *:www (LISTEN) apache2 14573 www-data 3u IPv4 92108840 0t0 TCP *:www (LISTEN)
Do I need to kill these processes first? Is that safe? Or is there another way to keep Flask running on port 5000 but have the main website domain redirect somehow?
To change the host and port, pass them as options to the command. Pass --help for the full list of options. Setting the SERVER_NAME config will not affect the command either, as the command can't see the app's config. Never expose the dev server to the outside (such as binding to 0.0.
1- Stop other applications that are using port 80. 2- run application with port 80 :
if __name__ == '__main__': app.run(host='0.0.0.0', port=80)
For externally visible server, where you don't use apache or other web server you just type
flask run --host=0.0.0.0 --port=80
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With