uwsgi 配置


先贴个官方文档
安装python , 及虚拟环境, django 等
还要安装uwsgi

pip install uwsgi

现在先贴下现有项目目录结构


project.png

现在因为wsgi.py已经有django给生成了 .
我们只需要在项目目录, 即manage.py的同级目录创建文件myweb_uwsgi.ini


image.png
  • myweb_uwsgi.ini
[uwsgi]
# Django-related settings

socket = 192.16864.131.:8000

# the base directory (full path)
chdir           = /home/lin/Desktop/lin/code/workspace/partner


# Django s wsgi file
module          = partner.wsgi:application
# wsgi-file = myproject/wsgi.py

# process-related settings
# master
master          = true

# maximum number of worker processes
processes       = 4

# ... with appropriate permissions - may be needed
# chmod-socket    = 664
# clear environment on exit
vacuum          = true

daemonize       = /home/lin/Desktop/lin/code/workspace/partner/uwsgi_log.log
 
pidfile = /home/lin/Desktop/lin/code/workspace/partner/uwsgi_pid.log
image.png
  • [uwsgi] 必须有 , 不然会报以下错
 Can't find section "uwsgi" in INI configuration file myweb_uwsgi.ini

文件里面的字段意思:

  • socket :指定项目执行的端口号
    • 用nginx的时候就配socket , 直接运行的时候配 http
  • chadir :指定项目的目录
  • module :可以这么来理解,对于- myweb_uwsgi.ini文件来说,与它的平级的有一个partner目录,这个目录下有一个wsgi.py文件
  • master :允许主线程存在(true)
  • processes:开启的进程数量(这里是开启4个进程)
  • vacuum :当服务器退出的时候自动清理环境,删除unix socket文件和pid文件

配完就能运行起uwsgi了

uwsgi --ini myweb_uwsgi.ini 

最后贴一下nginx的配置了.

server {
    listen         8099;
    server_name    192.168.64.131
    charset UTF-8;
    access_log      /var/log/nginx/myweb_access.log;
    error_log       /var/log/nginx/myweb_error.log;

    client_max_body_size 75M;

    location / {
        include uwsgi_params;
        uwsgi_pass 192.168.64.131:8000;
        uwsgi_read_timeout 20;
    }
    location /static {
        expires 30d;
        autoindex on;
        add_header Cache-Control private;
        alias /home/lin/Desktop/lin/code/workspace/partner/static;
     }
 }

你可能感兴趣的:(uwsgi 配置)