一、假設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 # unix套接字文件路徑 socket =:8089 # 退出時清空環境 vacuum = true #每個進程開啓4個線程 threads = 2 #支持線程啓動 enable-threads = True #設置uwsgi後臺運行 daemonize = /var/www/html/exampleA/uwsgi.log