ArcherWong博客
首页
博客
Django Nginx+uwsgi 安装配置
作者:ArcherWong
分类:python
时间:2019-01-03 21:37:55
阅读:328
[TOC] 我们使用 python manage.py runserver 来运行服务器。这只适用测试环境中使用。 正式发布的服务,我们需要一个可以稳定而持续的服务器,比如apache, Nginx, lighttpd等,本文将以 Nginx 为例。 # 1 安装基础开发包 ## 1.1 Centos 下安装步骤如下: ``` yum groupinstall "Development tools" yum install zlib-devel bzip2-devel pcre-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel ``` ## 1.2 python包管理工具 pip 包: https://pypi.python.org/pypi/pip 安装 pip 的好处是可以用 pip list、pip uninstall 管理 Python 包, easy_install 没有这个功能,只有 uninstall。 # 2 安装 uwsgi uwsgi:https://pypi.python.org/pypi/uWSGI uwsgi 参数详解:http://uwsgi-docs.readthedocs.org/en/latest/Options.html pip install uwsgi uwsgi --version # 查看 uwsgi 版本 测试 uwsgi 是否正常: 新建 test.py 文件,内容如下: ``` def application(env, start_response): start_response('200 OK', [('Content-Type','text/html')]) return "Hello World" ``` 然后在终端运行: uwsgi --http :8001 --wsgi-file test.py 在浏览器内输入:http://xxx.xxx.xxx.xxx:8001,查看是否有"Hello World"输出,若没有输出,请检查你的安装过程。 # 3 uwsgi 配置 uwsgi支持ini、xml等多种配置方式,本文以 ini 为例, 首在/ect/uwsgi目录下uwsgi.ini,如果目录不存在自己创建 touch /etc/uwsgi/uwsgi.ini 添加如下配置: ``` [uwsgi] chdir=/data/PyLearn uid=nobody gid=nobody module=PyLearn.wsgi:application socket=/etc/uwsgi/uwsgi.sock master=true workers=5 pidfile=/etc/uwsgi/uwsgi.pid vacuum=true thunder-lock=true enable-threads=true harakiri=30 post-buffering=4096 daemonize=/var/log/uwsgi.log ``` # 4 与Nginx结合 修改nginx的配置文件,由配置文件可以看出uwsgi和php-fpm使用很像 ``` server{ server_name www.zhixin8.club zhixin8.club; listen 80; charset UTF-8; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; location / { include uwsgi_params; uwsgi_connect_timeout 30; uwsgi_pass unix:/etc/uwsgi/uwsgi.sock; } } ``` 设置完成后,在终端运行: ``` uwsgi --ini /etc/uwsgi/uwsgi.ini service nginx start ``` 在浏览器输入:http://127.0.0.1,你就可以看到 django 的 "It work" 了。
标签:
上一篇:
用swoole实现nginx日志解析
下一篇:
Django基本使用
文章分类
css
elasticsearch
git
golang
guacamole
javascript
letsencrypt
linux
nginx
other
php
python
vue
web
阅读排行
golang笔记---关联数组(map)
letsencrypt证书-管理工具certbot
centos7.3配置guacamole
golang笔记---template模板语法
nginx笔记-proxy_cache缓存详解
友情链接
node文件
laravel-vue
ArcherWong的博客园