1. 程式人生 > >centos+django+nginx+uwsgi 部署手記

centos+django+nginx+uwsgi 部署手記

1.安裝anaconda配置相關python環境
2.uwsgi配置
(1)安裝uwsgi

pip install uwsgi

Exception: you need a C compiler to build uWSGI

yum install -y gcc gcc-c++

(2)在django的setting檔案中,新增如下內容,以支援websocket

WEBSOCKET_FACTORY_CLASS = 'dwebsocket.backends.uwsgi.factory.uWsgiWebSocketFactory'

3.nginx配置
(1)安裝nginx

sudo yum install epel-release
sudo yum install nginx
sudo systemctl start nginx

https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-centos-7
(2)將專案nginx配置檔案加入到nginx的啟動配置檔案中

ln -s /your_project_nginx_path/**_nginx.conf /etc/nginx/conf.d/

(3)在django的setting檔案中,註釋掉STATICFILES_DIRS,新增下面一行內容:

STATIC_ROOT = os.path.join(BASE_DIR, "static/")

執行如下命令,拉取所有需要的static file 到同一個目錄:

python manage.py collectstatic

(4)執行nginx

sudo /usr/sbin/nginx