問題:
I have a Flask server running through port 5000, and it's fine.我有一個通過端口 5000 運行的 Flask 服務器,它很好。 I can access it at http://example.com:5000我可以在http://example.com:5000訪問它
But is it possible to simply access it at http://example.com ?但是是否可以簡單地在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.我假設這意味着我必須將端口從 5000 更改爲 80。但是當我在 Flask 上嘗試時,我在運行它時收到此錯誤消息。
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運行lsof -i :80
返回
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?或者是否有另一種方法可以讓 Flask 在端口 5000 上運行但以某種方式重定向主網站域?
解決方案:
參考一: https://en.stackoom.com/question/1MoIQ參考二: https://stackoom.com/question/1MoIQ