1. 程式人生 > >django+nginx+python3 生產環境部署

django+nginx+python3 生產環境部署

sgi 分離 lec 部署 home system access 重啟nginx server

一、安裝python基礎環境

  1.安裝各類基礎模塊

  yum install gcc-c++ wget openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel libxml* -y

  2.安裝python3環境

    2.1)下載python3.6包

        wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz

    2.2)解壓、安裝python3

        tar -zxvf Python-3.6.3.tar.gz && cd Python-3.6.3

        ./configure --prefix=/usr/local/python3 && make && make install

    3.3)python3相關命令添加系統環境中

        ln -s /usr/local/python3/bin/python3.6 /usr/bin/python3

        ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

   2.python3安裝django和uwsgi模塊

        pip3 install django==1.11.10

        pip3 install uwsgi

   3.寫好django項目打包上傳到服務器,修改setting.py

    ALLOWED_HOSTS = [‘*‘,] #允許所有ip訪問django項目

    DEBUG = False  #關閉DEBUG模式

    STATIC_ROOT=‘/home/CMS/mysite/static/‘ #配置靜態文件存放的目錄

   4.把django項目中的靜態文件分離出來

    python3 manage.py collectstatic

二、配置nginx訪問uwsgi

  

server {
listen 80;
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; #location / {
# root html;
# index index.html index.htm;
#}   #設置代理訪問   location / {
root /home/CMS;
include uwsgi_params;
proxy_pass http://127.0.0.1:8080;
uwsgi_read_timeout 30;
} 三、 使用nginx代理獲取靜態文件     location /static {
autoindex on;
alias /home/CMS/mysite/static/; #靜態文件訪問路徑
} 四、重啟nginx 和啟動django項目   python3 manage.py runserver 0.0.0.0:8080   #重啟django項目   systemctl restart nginx.service  #重啟nginx

    

django+nginx+python3 生產環境部署