Flask部署至云服务器
Posted 嚣张的小姜
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Flask部署至云服务器相关的知识,希望对你有一定的参考价值。
菜鸟须知
前面你已经经历了html+CSS+javascript等非人的折磨,也学会了Linux的操作。
现在就到了用Python-Flask作为后端程序部署到云服务器上,这样你的一个网页功能就已经实现了!
现在让我们来看看吧!
在步入正题之前,先来答两道题吧!
01
通常Flask部署的方法一般是?
点击空白处查看答案
1. linux sh & nohup后台运行python脚本
2. 使用flask + nginx + gunicorn
3. 使用screen命令部署
4. 使用flask + nginx + uwsgi
02
Gunicorn是什么?
点击空白处查看答案
Gunicorn ‘Green Unicorn’ 是一个 UNIX 下的 WSGI HTTP 服务器,它是一个 移植自 Ruby 的 Unicorn 项目的 pre-fork worker 模型。(绿色独角兽)

现在就来开始Gunicorn之路吧!
Let's go!
1.按照惯例先来安装这个Gunicorn
pip install gunicorn
#这个一般是python2条件下的;
pip3 install python3-gunicorn
#这个就可以省去很多麻烦;
安装好Gunicorn,你就搞好了90%
对,就是这么简单!!!
2.运行Gunicorn
gunicorn -w 2 -b 0.0.0.0:8080 app:app
这是运行Gunicorn最简单的命令
gunicorn -w 3 -b 0.0.0.0:8080 app:app --error-logfile=/logs/error.log --access-logfile=/logs/access.log -D
这是一般的命令格式
!important基本参数说明
参数 |
简化 |
说明 |
-bind |
-b |
IP及端口 |
-workers INT |
-w |
线程数 |
-error-logfile |
3.部署时遇到的问题!
遇到这些问题,二话不说,直接用我们祖传的排除法解决问题!(万能法)
好了,以上就是我在比赛中遇到的一个小问题,希望能对你们有所帮助。 |