Django + Uwsgi + Nginx 的生產環境部署

Django + Uwsgi + Nginx 的生產環境部署 javascript

參考網址:
http://www.javashuo.com/article/p-demqsemc-p.html
http://wuchengyi.com/post/1/css

Nginx 安裝配置
參考網址:http://www.runoob.com/linux/nginx-install-setup.htmlhtml

Centos下安裝nginx步驟解析
參考網址:http://www.javashuo.com/article/p-cjsaisae-m.htmljava

出現錯誤:(注意:查看日誌文件)
參考網址:https://blog.csdn.net/LY_Dengle/article/details/69568652node

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

[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.confnginx

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/;   # 關聯項目靜態文件
         }
    }
}
相關文章
相關標籤/搜索