北京SEO

linux中快速搭建nginx+uwsgi+flask环境

2019/10/10/17:46:29  阅读:2026  来源:谷歌SEO算法  标签: SEO工具

下文来为各位推荐一篇关于linux中快速搭建nginx+uwsgi+flask环境文章,希望这篇文章可以给各位带来帮助哦.

1.下载所需要的软件包

  1. wgethttp://nginx.org/download/nginx-1.5.9.tar.gz
  2. wgethttp://projects.unbit.it/downloads/uwsgi-2.0.4.tar.gz
  3. wgethttp://exim.mirror.fr/pcre/pcre-8.34.tar.gz

2.编译安装

  1. #安装pcre,Nginx的HTTPRewrite模块会用到
  2. tarzxvfpcre-8.34.tar.gz
  3. cdpcre-8.34/
  4. ./configure
  5. sudomake
  6. sudomakeinstall
  7. cd..
  8. #安装nginx------------------------------------------
  9. tar-zxvfnginx-1.5.9.tar.gz
  10. cdnginx-1.5.9
  11. ./configure--user=nobody--group=nobody--prefix=/usr/local/nginx--with-http_stub_status_module--with-cc-opt='-O3'--with-cpu-opt=opteron
  12. sudomake&&sudomakeinstall
  13. cd..
  14. #安装uwsgi-------------------------------------------
  15. tar-zxvfuwsgi-2.0.4.tar.gz
  16. cduwsgi-2.0.4
  17. sudomake
  18. vi/etc/ld.so.conf#添加动态链接库目录/usr/local/lib
  19. #添加行:/usr/local/lib
  20. ldconfig#使之生效
  21. cpuwsgi/usr/bin
  22. cd..
  23. #--------------------------------------------------
  24. #Flask,安装方式很多:yum、apt-get、pip
  25. sudopipinstallflask

3.编辑nginx和uwigi配置文件,nginx.conf配置.

  1. $cat/usr/local/nginx/conf/nginx.conf
  2. usernobody;
  3. worker_processes2;
  4. events{
  5. worker_connections1024;
  6. }
  7. http{
  8. includemime.types;
  9. default_typeapplication/octet-stream;
  10. #log_formatmain'$remote_addr-$remote_user[$time_local]"$request"'
  11. #'$status$body_bytes_sent"$http_referer"'
  12. #'"$http_user_agent""$http_x_forwarded_for"';
  13. #access_loglogs/access.logmain;
  14. sendfileon;
  15. #tcp_nopushon;
  16. #keepalive_timeout0;
  17. keepalive_timeout65;
  18. gzipon;
  19. server{
  20. listen80;
  21. server_name#记得做下本地hosts
  22. location/{
  23. uwsgi_pass127.0.0.1:9000;
  24. includeuwsgi_params;
  25. uwsgi_paramUWSGI_CHDIR/data/www.phpfensi.com/flask/yw;#网站目录可以选,因为uwsgi那还是要配置的
  26. uwsgi_paramUWSGI_SCRIPTrun;#run就是flask/yw目录下运行文件run.py
  27. access_logoff;
  28. }
  29. error_page500502503504/50x.html;
  30. location=/50x.html{
  31. roothtml;
  32. }
  33. #location~.php${
  34. #roothtml;
  35. #fastcgi_pass127.0.0.1:9000;
  36. #fastcgi_indexindex.php;
  37. #fastcgi_paramSCRIPT_FILENAME/scripts$fastcgi_script_name;
  38. #includefastcgi_params;
  39. #}
  40. }
  41. }

uwsgi.ini配置

方法1:

  1. $cat/usr/local/nginx/conf/uwsgi_ini
  2. [uwsgi]
  3. socket=0.0.0.0:9000
  4. master=true
  5. pidfile=/usr/local/nginx/uwsgi.pid
  6. processes=8
  7. workers=2
  8. chdir=/data/www.phpfensi.com/flask/yw#网站目录
  9. callable=app#这个就是run.py里的app,youknow!
  10. pythonpath=/data/www.phpfensi.com/flask
  11. profiler=true
  12. memory-report=true
  13. enable-threads=true
  14. logdate=true
  15. limit-as=6048
  16. daemonize=/data/logs/flask.log#run.py运行后产生的信息都记录在这的flask.log日志文件里

方法2:

  1. [uwsgi]
  2. socket=0.0.0.0:9000
  3. pidfile=/usr/local/nginx/uwsgi.pid
  4. processes=8
  5. master=true
  6. chdir=/data/www.phpfensi.com/flask/yw#网站目录
  7. #module=run#这个就是run.py
  8. callable=app#这个就是run.py里的app,youknow!
  9. pythonpath=/data/www.phpfensi.com/flask

4.运行和停止uwsgi和nginx

  1. sudo/usr/bin/uwsgi--ini/usr/local/nginx/conf/uwsgi.ini
  2. sudosudo/usr/local/nginx/sbin/nginx
  3. #kill
  4. sudokillallnginx
  5. sudokillall-9uwsgi

广告内容

linux中快速搭建nginx+uwsgi+flask环境 linux中快速搭建nginx+uwsgi+flask环境 linux中快速搭建nginx+uwsgi+flask环境

相关阅读

热门评论

卢松松博客 卢松松博客

关注创业者、自媒体人和站长的网站

总篇数167

精选文章

RMAN中catalog和nocatalog区别介绍 小技巧:为Linux下的文件分配多个权限 zimbra8.5.1安装第三方签名ssl证书的步骤 解决mysql不能远程连接数据库方法 windows服务器mysql增量备份批处理数据库 mysql中slow query log慢日志查询分析 JavaScript跨域问题总结 Linux下负载均衡软件LVS配置(VS/DR)教程 mysql中权限参数说明 MYSQL(错误1053)无法正常启动

SEO最新算法