nginx配置+uwsgi+負載均衡配置

誠實善良小郎君發表於2018-06-24

nginx靜態檔案配置

location /static{
            alias  /var/www/myApp/static;
        }
sudo mkdir -vp /var/www/myApp/static/
sudo chmod 777 /var/www/myApp/static/

#工程目錄settings下配置靜態檔案
STATIC_ROOT = `/var/www/myApp/static`
STATIC_URL = `/static/`

#遷移靜態檔案
python manage.py collectstatic

#settings目錄中
DEBUG = Flase
ALLOW_HOST = [`*`]

nginx + 反向代理 + runserver

location / {
           proxy_pass http://www.pipixia957.cn:8000;  #反向代理設定
           proxy_set_header X-real-ip $remote_addr;
           proxy_set_header Host $http_host;
        }


[uwsgi]
http=0.0.0.0:8000
chdir=/home/ubuntu/pro/project
wsgi-file=project/wsgi.py
processes=2
threads=2
master=True
pidfile=uwsgi.pid
daemonize=uwsgi.log

runserver啟動
#訪問不需要加埠

nginx + uwsgi啟動

 location / {
            include uwsgi_params;
            uwsgi_pass www.pipixia957.cn:8000;
        }
 
[uwsgi]
socket=0.0.0.0:8000
chdir=/home/ubuntu/pro/project
wsgi-file=project/wsgi.py
processes=2
threads=2
master=True
pidfile=uwsgi.pid
daemonize=uwsgi.log

#訪問不需要再加埠

nginx + 負載均衡

upstream mycom{
    ip_hash;
    server 10.11.0.1:8000;  #負載均衡伺服器群
    server 10.11.0.1:8000;
    server 10.11.0.1:8000  down;
}

location / {   
            include uwsgi_params;
            uwsgi_pass mycom; #連線負載均衡伺服器
        }

相關文章