zoukankan      html  css  js  c++  java
  • 使用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

  • 相关阅读:
    java前三章总结
    Java入门第二章
    MYSQL 3306设置允许外网访问
    Lnmp Laravel搭建网站需要注意的几点:
    Linux 如何删除网站目录下的user.ini
    Linux Composer的安装
    lnmp切换PHP版本
    解决GitHub的raw.githubusercontent.com无法连接问题
    Linux 7系列默认不能连网的解决办法
    lnmp安装
  • 原文地址:https://www.cnblogs.com/liruixin/p/10574987.html
Copyright © 2011-2022 走看看