在项目根目录中创建uwsgi.ini文件:
[uwsgi]
#nginx连接使用socket
socket=192.168.43.110:8000
#直接请求
#http=http://192.168.43.110:8000
#项目根目录
chdir=/home/jack-yun/dailyfresh
wsgi-file=dailyfresh/wsgi.py
#processes=4
#threads=2
workers=2
reload-mercy=10
vacuum=true
master=true
buffer-size=65535
#启动、停止、加载uwsgi
pidfile=uwsgi.pid
daemonize=uswgi.log
harakiri = 20 # respawn processes taking more than 20 seconds
limit-as = 512 # limit the project to 128 MB
max-requests = 5000 # respawn processes after serving 5000 requests
/usr/local/webserver/nginx/sbin groupadd www
/usr/local/webserver/nginx/sbin useradd -g www www
进入/usr/local/nginx/conf/nginx.conf,配置Nginx
user www www;
worker_processes 2; #设置值和CPU核心数一致
#pid /run/nginx.pid;
worker_rlimit_nofile 65535;
include /etc/nginx/modules-enabled/*.conf;
events {
#use epoll;
worker_connections 65535;
#worker_connections 768;
# multi_accept on;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
types_hash_max_size 2048;
keepalive_timeout 60;
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;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;
server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
#error_log /var/log/nginx/error.log;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
##
# Gzip Settings
##
gzip on;
gzip_vary on;
gzip_min_length 1k;
# gzip_proxied any;
gzip_comp_level 2;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
#include /etc/nginx/conf.d/*.conf;
#include /etc/nginx/sites-enabled/*;
server
{
listen 80;#监听端口
server_name localhost 192.168.43.110;
charset utf-8;
client_max_body_size 75M;
location / {
include /etc/nginx/uwsgi_params;
uwsgi_pass 192.168.43.110:8000;
uwsgi_param UWSGI_SCRIPT dailyfresh.wsgi; #//入口文件,即wsgi.py相对于项目根目录的位置,“.”相当于一层目录
uwsgi_param UWSGI_CHDIR /dailyfresh; #//项目根目录
index index.html index.htm;
client_max_body_size 35m;
}
location /static {
alias /home/jack-yun/static;
}
}
}
启动nginx服务:/usr/local/webserver/nginx/sbin/nginx
进入Django根目录,配置STATIC_ROOT = os.path.join(BASE_DIR, '服务器中的目录')
(STATIC_ROOT 文件夹 是用来将所有STATICFILES_DIRS中所有文件夹中的文件,以及各app中static中的文件都复制过来)
收集静态文件:python manage.py collectstatic
然后ps -ef | grep uwsgi
查看是否有uwsgi服务启动,有就kill -9 进程号
启动uwsgi服务:uwsgi --ini uwsgi.ini