博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【Flask】flask+uwsgi+nginx环境部署
阅读量:4637 次
发布时间:2019-06-09

本文共 2879 字,大约阅读时间需要 9 分钟。

在centos上,部署flask框架的环境,我选择了uwsgi和nginx

具体步骤为:

配置nginx+uwsgi

安装nginx  nginx/1.12.2
安装Flask  0.10.1
安装uwsgi  2.0.16(64bit)
安装uwsgi-plugin-python 2.0.16

创建一个flask项目

1 #!/usr/bin/python 2 # coding=utf-8 3  4 from flask import Flask 5 import sys 6 reload(sys) 7  8 print sys.path 9 sys.path.append('/home/MySite')10 sys.setdefaultencoding('utf-8')11 12 app = Flask(__name__)13 14 15 @app.route('/')16 def hello_world():17     return '澳门最大在线赌场开业了!!!美女荷官在线发牌!'18 19 20 if __name__ == '__main__':21     app.run(port=8080,debug=True)

测试一下flask是否能够显示

注意

flask直接运行,只能在一台电脑上看到,因为是单线程的。
app.run(host='0.0.0.0',port=80)
腾讯云安全组中打开80端口即可访问。
其它主机应该类似。host中填公网地址无法启动。
ps..澳门xx会被腾讯云拦截。。。请换个健康和谐的内容
 
创建ini文件
1 [uwsgi] 2 base =/home/MySite    3 callable = app     #这个必须写,不然会报找不到application 4 socket = :8081    #开启的端口,与nginx一致 5 chdir =/home/MySite/   #指定项目路径 6 wsgi-file =MySite.py    #指定flask运行的文件,是一个相对路径 7 processes = 4   #4个进程,每个进程2个线程 8 threads = 2 9 chmod-socket = 66610 plugins=python   #安装uwsgi-plugin-python后需要添加的一个参数11 daemonize = mysite.log    #让uwsgi后台运行的,输出为一个Log12 #stats = :8082

 

修改nginx配置文件

1 user nginx; 2 worker_processes auto; 3 error_log /var/log/nginx/error.log; 4 pid /run/nginx.pid; 5  6 # Load dynamic modules. See /usr/share/nginx/README.dynamic. 7 include /usr/share/nginx/modules/*.conf; 8  9 events {10     worker_connections 1024;11 }12 13 http {14     log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '15                       '$status $body_bytes_sent "$http_referer" '16                       '"$http_user_agent" "$http_x_forwarded_for"';17 18     access_log  /var/log/nginx/access.log  main;19 20     sendfile            on;21     tcp_nopush          on;22     tcp_nodelay         on;23     keepalive_timeout   65;24     types_hash_max_size 2048;25 26     include             /etc/nginx/mime.types;27     default_type        application/octet-stream;28 29     # Load modular configuration files from the /etc/nginx/conf.d directory.30     # See http://nginx.org/en/docs/ngx_core_module.html#include31     # for more information.32     include /etc/nginx/conf.d/*.conf;33 34     server {35         listen       80;36         server_name  localhost;37         location / {38         include /etc/nginx/uwsgi_params;39         uwsgi_pass 127.0.0.1:8081;    #与ini文件对应40         uwsgi_param UWSGI_CHDIR /home/MySite;41         #uwsgi_param UWSGI_SCRIPT View:app;42         #uwsgi_param SCRIPT_NAME /;43         #uwsgi_pass unix:/home/MySite/uwsgi.sock;44         }45 46         error_page 404 /404.html;47             location = /40x.html {48         }49 50         error_page 500 502 503 504 /50x.html;51             location = /50x.html {52         }53     }54   }

 

uwsgi启动命令,如果不写绝对路径需要在ini文件当前路径执行
1 uwsgi --ini abc.ini

 

nginx启动命令
/usr/sbin/nginx -c /etc/nginx/nginx.conf

 

启动这两个服务,就可以正常访问你的flask内容了。
 
 
 
 

 

转载于:https://www.cnblogs.com/ArmoredTitan/p/9164054.html

你可能感兴趣的文章
Android初学第36天
查看>>
Some configure
查看>>
json_encode时中文编码转正常状态
查看>>
流量调整和限流技术 【转载】
查看>>
Axure 全局辅助线(转)
查看>>
正由另一进程使用,因此该进程无法访问此文件。
查看>>
1 线性空间
查看>>
VS不显示最近打开的项目
查看>>
MyEclipse安装Freemarker插件
查看>>
计算多项式的值
查看>>
DP(动态规划)
查看>>
chkconfig
查看>>
TMS320F28335项目开发记录2_CCS与JTAG仿真器连接问题汇总
查看>>
最强的篮球队和马尔可夫模型
查看>>
hdu-4302-Holedox Eating-线段树-单点更新,有策略的单点查询
查看>>
cocos2d-x 音效中断问题
查看>>
子分类账知识学习(汇总网上比较有用的资料)
查看>>
pyQt 每日一练习 -- 登录框
查看>>
wp 删除独立存储空间文件(多级非空文件夹删除)
查看>>
Loadrunner安装使用入门
查看>>