Django + Uwsgi + Nginx 的生产环境部署

Django + Uwsgi + Nginx 的生产环境部署 

参考网址:
https://www.cnblogs.com/chenice/p/6921727.html
http://wuchengyi.com/post/1/

Nginx 安装配置
参考网址:http://www.runoob.com/linux/nginx-install-setup.html

Centos下安装nginx步骤解析
参考网址:https://www.cnblogs.com/angellating/p/6479876.html

出现错误:(注意:查看日志文件)
参考网址:https://blog.csdn.net/LY_Dengle/article/details/69568652

uwsgi.ini (注意:http=0.0.0.0:8080 的端口不能和nginx:80的端口冲突)

[uwsgi]
# 项目目录
chdir=/root/myproject/

# 指定项目的application
module=myproject.wsgi:application
# 指定sock的文件路径       
socket=127.0.0.1:8000
# 进程个数       
workers=5
pidfile=/root/myproject/script/uwsgi.pid
# 指定IP端口       
http=0.0.0.0:8080
# 指定静态文件
static-map=/static=/root/myproject/static
# 启动uwsgi的用户名和用户组
uid=root
gid=root
# 启用主进程
master=true
# 自动移除unix Socket和pid文件当服务停止的时候
vacuum=true
# 序列化接受的内容,如果可能的话
thunder-lock=true
# 启用线程
enable-threads=true
# 设置自中断时间
harakiri=30
# 设置缓冲
post-buffering=4096
# 设置日志目录
daemonize=/root/myproject/script/uwsgi.log

/usr/loacl/nginx/conf:nginx.conf

user www www;
worker_processes 2; #设置值和CPU核心数一致
error_log /usr/local/nginx/logs/nginx_error.log crit; #日志位置和日志级别
pid /usr/local/nginx/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
events
{
  use epoll;
  worker_connections 65535;
}
http
{
  include mime.types;
  default_type application/octet-stream;
  log_format main  '$remote_addr - $remote_user [$time_local] "$request" '
               '$status $body_bytes_sent "$http_referer" '
               '"$http_user_agent" $http_x_forwarded_for';

#charset gb2312;

  server_names_hash_bucket_size 128;
  client_header_buffer_size 32k;
  large_client_header_buffers 4 32k;
  client_max_body_size 8m;

  sendfile on;
  tcp_nopush on;
  keepalive_timeout 60;
  tcp_nodelay on;
  fastcgi_connect_timeout 300;
  fastcgi_send_timeout 300;
  fastcgi_read_timeout 300;
  fastcgi_buffer_size 64k;
  fastcgi_buffers 4 64k;
  fastcgi_busy_buffers_size 128k;
  fastcgi_temp_file_write_size 128k;
  gzip on; 
  gzip_min_length 1k;
  gzip_buffers 4 16k;
  gzip_http_version 1.0;
  gzip_comp_level 2;
  gzip_types text/plain application/x-javascript text/css application/xml;
  gzip_vary on;

  #limit_zone crawler $binary_remote_addr 10m;
  #下面是server虚拟主机的配置
  server {
        listen         80; 
        server_name    监听端口;
        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 127.0.0.1:8000;  # 和uwsgi的socket配置保持一致
            uwsgi_read_timeout 2;
        }   
        location /static {
            expires 30d;
            autoindex on; 
            add_header Cache-Control private;
            alias /root/myproject/static/;   # 关联项目静态文件
         }
    }
}

 

posted @ 2018-10-26 10:29  你知道  阅读(164)  评论(0编辑  收藏  举报