一、假设nginx的安装目录为/usr/local/nginx
搭载多个web站点,在安装目录下新建一个文件夹vhost,路径为:/usr/local/nginx/vhost
该文件下存放不同web的配置,再次只写一个,其他雷同
server {
# 监控端口,对于nginx的web站点,可以相同,nginx依据路径区分访问的web
listen 8002;
server_name localhost;
#charset koi8-r;
charset utf-8;
#access_log logs/host.access.log main;
access_log /var/log/nginx/exampleA_access.log;
error_log /var/log/nginx/exampleA_error.log;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8089; #与uwsgi.ini保持一致
}
location /static/ {
alias /var/www/html/exampleA/static/;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
二、nginx.conf的配置(路径为/usr/local/nginx/conf)
#user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
# 加载不同web的配置
include /usr/local/nginx/vhost/*.conf;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
# 假设服务器上同时运行apache,nginx避开80端口
listen 8001;
}
}
二、下面附加django的uwsgi的配置。
[uwsgi]
# 项目根目录路径(full path)
chdir = /var/www/html/exampleA
# Django的 wsgi 文件
module = exampleA.wsgi
master = true
# 最大工作进程数(CPU密集型建议设为CPU核心数,IO密集型建议设为CPU核心数的两倍)
processes = 4
buffer-size = 65536
# 立即在服务器上reload
py-autoreload = 1
#每个进程开启1个线程
threads = 1
# unix套接字文件路径
socket =:8089
# 退出时清空环境
vacuum = true
# 以固定的文件大小(单位KB),切割日志文件
log-maxsize = 100000
# 不记录请求信息的日志
disable-logging = true
#支持线程启动
enable-threads = True
#设置uwsgi后台运行
daemonize = /var/www/html/exampleA/uwsgi.log