您好,登錄后才能下訂單哦!
這篇文章主要介紹Centos如何部署django服務nginx+uwsgi,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
1.安裝python3
yum -y install wget gcc make zlib-devel readline-devel bzip2-devel ncurses-devel sqlite-devel gdbm-devel xz-devel tk-devel openssl-devel wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz xz -d Python-3.6.1.tar.xz tar -xvf Python-3.6.1.tar cd Python-3.6.1 ./configure --prefix=/usr/local/python3.6 --enable-optimizations make make install ln -s /usr/local/python3.6/bin/python3 /usr/bin/python3 ln -s /usr/local/python3.6/bin/pip3 /usr/bin/pip3
這是通過編譯的方式來安裝的
輸入 python3 –version 和 pip3 –version 進行測試
2. 安裝nginx
sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm sudo yum install -y nginx sudo systemctl start nginx.service
通過你的域名或IP來訪問你的Web頁面來預覽一下Nginx的默認頁面進行測試
3.下載代碼,上傳到服務器的/var/www 目錄
4. 安裝依賴
pip3 install django pip3 install uwsgi ln -s /usr/local/python3/bin/uwsgi /usr/bin/uwsgi3
5. 獨立運行進行測試
cd /var/www/dexundjango python3 manage.py runserver 0.0.0.0:8014
測試通過后,Ctrl + C 停止運行
6.uwsgi
sudo mkdir -p /etc/uwsgi/sites sudo mkdir -p /var/log/uwsgi cd /etc/uwsgi/sites sudo vi /etc/uwsgi/sites/mysite.ini
[uwsgi] socket = 127.0.0.1:10000 chdir=/var/www/dexundjango module=mysite.wsgi:application master=True pidfile=/tmp/project-master.pid vacuum=True max-requests=5000 daemonize=/var/log/uwsgi/mysite.log
7. nginx 配置
vi /usr/local/nginx/conf/nginx.conf (根據本地的配置路徑) find / -name uwsgi_params 來替換下面的uwsgi_params路徑
server { listen 8014; #暴露給外部訪問的端口 server_name localhost; charset utf-8; location / { include /usr/local/nginx/conf/uwsgi_params; uwsgi_pass 127.0.0.1:10000; # 必須和uwsgi.ini配置的端口一致 } location /static/ { alias /home/www/dexundjango/trade/static/; #項目靜態路徑設置 }
8. 啟動uwsgi
uwsgi3 --ini /etc/uwsgi/sites/mysite.ini
9. 開機啟動uwsgi
vi /etc/init.d/uwsgi
#!/bin/bash # chkconfig: - 85 15 uwsgi=/usr/bin/uwsgi3 api_conf=/etc/uwsgi/sites/mysite.ini case $1 in start) echo -n "Starting uWsgi" nohup $uwsgi -i $api_conf >/var/log/uwsgi/project-api.log 2>&1 & echo " done" ;; stop) echo -n "Stopping uWsgi" killall -9 uwsgi echo " done" ;; restart) $0 stop $0 start ;; show) ps -ef|grep uwsgi ;; *) echo -n "Usage: $0 {start|restart|stop|show}" ;; esac
chmod +x /etc/init.d/uwsgi chkconfig --add uwsgi chkconfig uwsgi on
以上是“Centos如何部署django服務nginx+uwsgi”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。