Python2—0805筆記

9 部署上線uwsgi+nginx+django


centos 安裝python3.6html

下載 wget wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgzpython

安裝  tar xvf Python-3.7.2.tgzlinux

安裝   cd Python-3.7.2nginx

            ./configure –prefix=/usr/local/python3.7django

           make && make installvim

配置軟鏈接centos

  1. ln -s /etc/python/python3/bin/python3.7 /usr/bin/python3app

  2. ln -s /etc/python/python3/bin/pip3 /usr/bin/pip3socket

測試 輸入python3 -Vpost

安裝uwsgi

pip3 install uwsgj

[root@jerrylinux01 Python-3.7.2]# find / -name uwsgi

/etc/python/python3/bin/uwsgi

[root@jerrylinux01 Python-3.7.2]# ln -s /usr/local/python3/bin/uwsgi /usr/bin/uwsgi

測試

vim test.py

\# test.pydef application(env, start_response):

    start_response('200 OK', \[('Content-Type','text/html')\])

    return \[b"Hello World"\]

uwsgi –http :8001 –wsgi-file test.py

訪問192.168.78.128:8001

安裝django

pip3 install Django==1.8.9

uwsg.ini代碼

\[uwsgi\]

\# 項目目錄

chdir=/mnt/www/pachong

\# 指定項目的application

module=CMDB.wsgi:application

\# 指定sock的文件路徑       

socket=/mnt/www/django_uwsgi.sock

\# 進程個數       

workers=4

pidfile=/mnt/www/uwsgi.pid

\# 指定IP端口       

http=0.0.0.0:8080

\# 指定靜態文件

static-map=/static=/mnt/www/pachong/arya/static

\# 啓動uwsgi的用戶名和用戶組

uid=root

gid=root

\# 啓用主進程

master=true

\# 自動移除unix Socket和pid文件當服務中止的時候

vacuum=true

\# 序列化接受的內容,若是可能的話

thunder-lock=true

\# 啓用線程

enable-threads=true

\# 設置自中斷時間

harakiri=30

\# 設置緩衝

post-buffering=4096

\# 設置日誌目錄

daemonize=/mnt/www/django_uwsgi.log

#logto = /mnt/www/django.log

nginx

vhosts.conf代碼

server {

    listen      80;

    server_name localhost

    charset     utf-8;

    client\_max\_body_size 75M;

    location /media  {

        alias /path/to/project/media;

    }

    location /static {

        #alias /path/to/project/static;

        alias /mnt/www/pachong/arya/static;

    }

    location / {

        uwsgi\_pass  unix:///mnt/www/django\_uwsgi.sock;

        #include     /etc/nginx/uwsgi_params;

        #include     /mnt/server/nginx/conf/uwsgi_params;

        include     uwsgi_params;

        uwsgi\_read\_timeout  30;

    }

}
相關文章
相關標籤/搜索