flask部署
1、远程访问hello.py文件,文件内容大致如下:
# hello.py
from flask import Flask
app = Flask(__name__)
@app.route("/")
def index():
return "<h1>hello flask</h1>"
if __name__ == "__main__":
app.run()
2、启动nginx,我这个地方是创建了软链接的,你们运行的时候找到nginx的安装路径去运行,如果没有安装nginx,先去安装,可以看我另一篇博客
https://blog.csdn.net/qq_44739762/article/details/100085261。
sudo nginx
3、进入虚拟环境(虚拟环境的安装可以看本人另一篇博客
https://blog.csdn.net/qq_44739762/article/details/100163746),安装gunicorn。
pip install gunicorn
4、启动gunicorn,端口号自己指定,指定之后去服务器所在防火墙添加端口。
gunicorn -w 4 -b 服务器的私有ip:5000 运行文件名称:Flask程序实例名
例如,我的是这样:
gunicorn -w 4 -b xxx.xxx.xxx.xxx:5000 hello:app
5、浏览器远程访问。
服务器的公网ip
6、部署完成。