1. 程式人生 > >nginx__的簡單搭建和 wsgi

nginx__的簡單搭建和 wsgi

4 部署
    1 配置 uwsig(配置檔案)
        1 mkdir uwsgi
        2 cd uwsgi
        3 touch test_uwsig.ini
            [uwsgi]
            #  指定和nginx通訊的埠
            socket=127.0.0.1:9001
            # 專案路徑
            chdir=/home/tarena/myproject/friutday_1
            # wsgi.py 路徑
            wsgi-file=friutday/wsgi.py
            
#程序數 processes=4 #執行緒數 thread=2 # 自己佔用(uwsgi)的埠,可以任意 stats=127.0.0.1:8081 2 配置nginx 進入 cd /etc/nginx/sites-enabled/ 建立一個nginx 的 conf檔案 任意取名 (project_nginx.conf) vi project_nginx.conf server{
# 需要監聽的埠 ,, 瀏覽器訪問埠 listen 9000; # 如果有域名就是買的域名 server_name frituday.com; charset utf-8; # 載入靜態檔案的路徑 location /static{ alias /home/tarena/18070project/friutday_1/static;} location /{ # 在nginx裡面的檔案uwsgi_params
include uwsgi_params; # 跟uwsgi通訊的埠 uwsgi_pass 127.0.0.1:9001; } } 3 重啟nginx服務 sudo /etc/init.d/nginx restart 4 拷貝uwsgi_params檔案到專案路徑下 sudo cp /etc/nginx/uwsgi_params /home/tarena/18070project/friutday_1 3 收集靜態檔案 1 在settings.py中新增路徑(STATIC_ROOT) 可以不用新增,收集的時候會自動建立 STATIC_ROOT = '/home/.../static' 2 收集靜態檔案 python3 manage.py collectstatic 4 uwsgi 啟動專案 cd /home/tarena/uwsgi uwsgi --ini test_uwsgi.ini 3 多專案部署 1 uwsgi 每個專案需要單獨建立 uwsgi配置檔案,選用不同的埠 2 nginx 配置檔案, 在原來的基礎上新增 server{} 就可以