django uwsgi nginx组合范例

一、配置uwsgi启动文件

vi /etc/uwsgi_socket.ini

[uwsgi]
master = true
# 非多站模式时 vhost = true 和 no-site = true 需要注释掉,否则后续 nginx 配置文件中设置的入口文件则不生效,服务器会回应 Internal Server error
# vhost = true
# no-site = true
# the base directory (full path)
chdir = /var/cache/uwsgi
# maximum number of worker processes
processes = 3
# the socket (use the full path to be safe
socket = /var/cache/uwsgi/uwsgi.sock
# pid file
pidfile = /var/log/uwsgi/uwsgi.pid
# log file
daemonize = /var/log/uwsgi/uwsgi.log
# ... with appropriate permissions - may be needed
chmod-socket = 664
# clear environment on exit
vacuum = true
uid=nginx
gid=nginx

二、配置nginx部署django_project项目

vi /etc/nginx/conf.d/www.test.com.conf

server {

listen 80;
server_name www.test.com;

charset utf-8;
access_log /var/log/nginx/www.test.com.access.log main;
error_log /var/log/nginx/www.test.com.error.log warn;

client_max_body_size 75M;

location /static {
alias /opt/django_project/static;
}

location / {
include uwsgi_params;
uwsgi_pass unix:///var/cache/uwsgi/uwsgi.sock;
uwsgi_param UWSGI_CHDIR /opt/django_project;
uwsgi_param UWSGI_MODULE django_project.wsgi;
# uwsgi_param UWSGI_PYHOME /opt/django_projectenv;
}
}

三、生效服务

uwsgi --ini /etc/uwsgi_socket.ini

nginx -s start 或者 nginx - s reload

You may also like...

发表评论