美文网首页Linux学习
flask+Gunicorn部署外网无法访问

flask+Gunicorn部署外网无法访问

作者: frankie_cheung | 来源:发表于2019-03-06 15:37 被阅读0次

参考文章:

from flask import Flask
app = Flask(__name__)
@app.route('/get_one_haha')
def index():
    return 'hello world'
if __name__ == '__main__':
    app.run(host='0.0.0.0',port=5000)
  • 假如你是买的云服务器(阿里/腾讯/华为等等),记得把端口安全组打开,这个每一家的打开都不太一样,略去不表。
  • 设置host为0.0.0.0,
    设置gunicorn的配置
bind = "0.0.0.0:5000"
daemon = True

这两行代码是:默认ip可以访问,和后台运行,守护进程方式,就是类似于Linux的nohup
这样的话开始启动gunicorn
gunicorn -c 配置文件.py 执行文件名:app
查询:ps aux|gerp gunicorn,假如有进程就是运行了。

捕获.PNG
然后外网访问时写的是你云服务器公网ip:

相关文章

网友评论

    本文标题:flask+Gunicorn部署外网无法访问

    本文链接:https://www.haomeiwen.com/subject/beetpqtx.html