I'm developing a site with Python and Flask and want to move from localhost in my browser to my team's development server and development site but I'm having problems. I've already looked at the Flask documentation, which recommends using host='0.0.0.0'
or specifying SERVER_NAME
. Thusfar, neither of these things have helped. Here's a bit of code to show what I'm doing:
app = Flask(__name__)
if __name__ == '__main__':
app.secret_key = 'super secret key'
app.config['SERVER_NAME'] = 'https://example.org/blah'
app.run(host=app.config['SERVER_NAME'], port=4343, debug=True)
As you can see, instead of localhost:500
, I want to be able to go into my browser and visit 'https://example.org/blah'
and see the same things.
With this piece of code, I get this error:
(py34)user:~/flask$ python app.py
INFO - Connection with server established!
INFO - Server version meets recommendations (v2.9)
Traceback (most recent call last):
File "app.py", line 18, in <module>
app.run(host=app.config['SERVER_NAME'], port=4343, debug=True)
File "/home/me/anaconda3/envs/py34/lib/python3.4/site-packages/flask/app.py", line 772, in run
run_simple(host, port, self, **options)
File "/home/me/anaconda3/envs/py34/lib/python3.4/site-packages/werkzeug/serving.py", line 674, in run_simple
s.bind((hostname, port))
socket.gaierror: [Errno -2] Name or service not known
If instead of using SERVER_NAME
I use host='0.0.0.0'
, I don't get any errors and it will successfully start "Running on http://0.0.0.0:4343/"
but I can't follow that url into my browser the same way I can when I connect to my localhost.
What do I need to do to get my flask app running on https://example.org/blah
?
Also, if it helps to know, I have to ssh
into my server.
答案 0 :(得分:4)
如果您从服务器运行host='0.0.0.0'
,则应该可以导航到example.org:4343
并查看您的应用。
此外,SERVER_NAME
需要端口,符合documentation:
服务器的名称和端口号。子域名支持需要(例如:&#39; myapp.dev:5000&#39;)
最后,如果您想要显示没有端口号的应用,您需要使用root权限在端口80(或443)上运行它,或使用Nginx / Apache将请求从您的域路由到应用程序。