linux中快速搭建nginx+uwsgi+flask环境
2019/10/10/17:46:29 阅读:2026 来源:谷歌SEO算法 标签:
SEO工具
下文来为各位推荐一篇关于linux中快速搭建nginx+uwsgi+flask环境文章,希望这篇文章可以给各位带来帮助哦.
1.下载所需要的软件包
- wgethttp://nginx.org/download/nginx-1.5.9.tar.gz
- wgethttp://projects.unbit.it/downloads/uwsgi-2.0.4.tar.gz
- wgethttp://exim.mirror.fr/pcre/pcre-8.34.tar.gz
2.编译安装
- #安装pcre,Nginx的HTTPRewrite模块会用到
- tarzxvfpcre-8.34.tar.gz
- cdpcre-8.34/
- ./configure
- sudomake
- sudomakeinstall
- cd..
- #安装nginx------------------------------------------
- tar-zxvfnginx-1.5.9.tar.gz
- cdnginx-1.5.9
- ./configure--user=nobody--group=nobody--prefix=/usr/local/nginx--with-http_stub_status_module--with-cc-opt='-O3'--with-cpu-opt=opteron
- sudomake&&sudomakeinstall
- cd..
- #安装uwsgi-------------------------------------------
- tar-zxvfuwsgi-2.0.4.tar.gz
- cduwsgi-2.0.4
- sudomake
- vi/etc/ld.so.conf#添加动态链接库目录/usr/local/lib
- #添加行:/usr/local/lib
- ldconfig#使之生效
- cpuwsgi/usr/bin
- cd..
- #--------------------------------------------------
- #Flask,安装方式很多:yum、apt-get、pip
- sudopipinstallflask
3.编辑nginx和uwigi配置文件,nginx.conf配置.
- $cat/usr/local/nginx/conf/nginx.conf
- usernobody;
- worker_processes2;
- events{
- worker_connections1024;
- }
- http{
- includemime.types;
- default_typeapplication/octet-stream;
- #log_formatmain'$remote_addr-$remote_user[$time_local]"$request"'
- #'$status$body_bytes_sent"$http_referer"'
- #'"$http_user_agent""$http_x_forwarded_for"';
- #access_loglogs/access.logmain;
- sendfileon;
- #tcp_nopushon;
- #keepalive_timeout0;
- keepalive_timeout65;
- gzipon;
- server{
- listen80;
- server_name#记得做下本地hosts
- location/{
- uwsgi_pass127.0.0.1:9000;
- includeuwsgi_params;
- uwsgi_paramUWSGI_CHDIR/data/www.phpfensi.com/flask/yw;#网站目录可以选,因为uwsgi那还是要配置的
- uwsgi_paramUWSGI_SCRIPTrun;#run就是flask/yw目录下运行文件run.py
- access_logoff;
- }
- error_page500502503504/50x.html;
- location=/50x.html{
- roothtml;
- }
- #location~.php${
- #roothtml;
- #fastcgi_pass127.0.0.1:9000;
- #fastcgi_indexindex.php;
- #fastcgi_paramSCRIPT_FILENAME/scripts$fastcgi_script_name;
- #includefastcgi_params;
- #}
- }
- }
uwsgi.ini配置
方法1:
- $cat/usr/local/nginx/conf/uwsgi_ini
- [uwsgi]
- socket=0.0.0.0:9000
- master=true
- pidfile=/usr/local/nginx/uwsgi.pid
- processes=8
- workers=2
- chdir=/data/www.phpfensi.com/flask/yw#网站目录
- callable=app#这个就是run.py里的app,youknow!
- pythonpath=/data/www.phpfensi.com/flask
- profiler=true
- memory-report=true
- enable-threads=true
- logdate=true
- limit-as=6048
- daemonize=/data/logs/flask.log#run.py运行后产生的信息都记录在这的flask.log日志文件里
方法2:
- [uwsgi]
- socket=0.0.0.0:9000
- pidfile=/usr/local/nginx/uwsgi.pid
- processes=8
- master=true
- chdir=/data/www.phpfensi.com/flask/yw#网站目录
- #module=run#这个就是run.py
- callable=app#这个就是run.py里的app,youknow!
- pythonpath=/data/www.phpfensi.com/flask
4.运行和停止uwsgi和nginx
- sudo/usr/bin/uwsgi--ini/usr/local/nginx/conf/uwsgi.ini
- sudosudo/usr/local/nginx/sbin/nginx
- #kill
- sudokillallnginx
- sudokillall-9uwsgi
热门评论