在没有端口的瓶颈请求 [英] Flask request without port in url

查看:165
本文介绍了在没有端口的瓶颈请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Ubuntu的EC2服务器,并希望运行一个瓶服务器。我想要使​​用我的域名api.example.com访问服务器,而不必包含端口号。现在,我可以通过执行api.example.com:5000 / ...成功访问服务器,但我无法弄清楚如何做api.example.com / ....



现在我只是直接运行flask服务器,使用python flask_server.py。

在flask_server.py中:

  if __name__ =='__main__':
app.run(host = 0.0.0.0)
#flask.Flask.runrel =nofollow> run 方法使用 port 可选参数:

  if __name__ =='__main__':
app.run(host =0.0.0.0,port = 80)

您可以对此进行测试,但对于生产,我强烈建议您阅读 deployment options 部分,其中详细介绍了使用各种前端WSGI服务器运行瓶子的方法。



<如果您需要帮助了解所有这些组件如何一起工作以及如何设置它们; 这个要点有一个很好的总结。



更新:主机参数必须是一个字符串。


I have an ubuntu EC2 server and want to run a flask server. I want to hit the server using my domain name, api.example.com, without having to include the port number. Right now, I can successfully access the server by doing api.example.com:5000/... but I can't figure out how to do api.example.com/....

Right now I'm just running the flask server directly, using python flask_server.py.

In flask_server.py:

if __name__ == '__main__':
    app.run(host=0.0.0.0)

解决方案

The run method takes a port optional argument:

if __name__ == '__main__':
    app.run(host="0.0.0.0", port=80)

You can do this for testing, but for production I highly recommend you read the deployment options section in the documentation which details ways to run flask with various front end WSGI servers.

If you need help understanding how all these components work together and how to set them up; this gist has a nice summary.

Update: The host param needs to be a string.

这篇关于在没有端口的瓶颈请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆