使用uwsgi啟動django項目


在 manage.py 同級目錄 創建 uwsgi.ini 文件 ,內容如下:

[uwsgi]
# 對外提供 http 服務的端口
http = :18123

#the local unix socket file than commnuincate to Nginx   用於和 nginx 進行數據交互的端口
socket = 127.0.0.1:8001

# the base directory (full path)  django 程序的主目錄
#chdir = /data/python_workspace/plant/cmdb_v1.1
chdir = /data/python_workspace/plant/Needforspeed/cmdb_v1.2
# Django's wsgi file
wsgi-file = AutoCmdb/wsgi.py

# maximum number of worker processes
processes = 4

#thread numbers startched in each worker process
threads = 2

#monitor uwsgi status  通過該端口可以監控 uwsgi 的負載情況
stats = 0.0.0.0:9191


# clear environment on exit
vacuum          = true

# 后台運行,並輸出日志
daemonize = /var/log/uwsgi.log

  nginx vhost 中創建 django.conf 文件

# the upstream component nginx needs to connect to
upstream django {
    # server unix:///path/to/your/mysite/mysite.sock; # for a file socket
    server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}


# configuration of the server
server {
    # the port your site will be served on
    listen      80;
    # the domain name it will serve for
    server_name ittl.dev.aixuexi.com; # substitute your machine's IP address or FQDN
    charset     utf-8;

    # max upload size
    client_max_body_size 75M;   # adjust to taste


#    if ($uri ~ a){
#                rewrite ^/(.*)$ gerrit.dev.aixuexi.com/$1 permanent;
#                }


    # Django media
    location /media  {
        alias /path/to/your/mysite/media;  # your Django project's media files - amend as required
    }
    rewrite /a/.*  http://gerrit.dev.aixuexi.com$uri   permanent;


    location /static {
        alias /data/python_workspace/plant/cmdb_v1.1/web/static; # your Django project's static files - amend as required
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django;
        include     /usr/local/nginx/conf/uwsgi_params; # the uwsgi_params file you installed
        uwsgi_connect_timeout 300s;
        uwsgi_read_timeout 300s;
        uwsgi_send_timeout 300s;
    }
                access_log  /data/logs/django_access.log  access;
                error_log   /data/logs/django_error.log error;

}

  安裝 uwsgi 模塊 /usr/local/python3/bin/pip3  install uwsgi

啟動項目  /usr/local/python3/bin/uwsgi  --ini  test-uwsgi.ini


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM