美文网首页
nginx + uwsgi部署django

nginx + uwsgi部署django

作者: BlueCat2016 | 来源:发表于2019-06-27 20:53 被阅读0次

    uwsgi与nginx安装过程:略

    django工程结构:


    image.png

    demosite_uwsgi.ini内容:

    [uwsgi]
    socket= :8080
    chdir=/root/test/demosite
    module=demosite.wsgi
    master=true
    processes=4
    vacuum=true
    

    nginx.conf

    # For more information on configuration, see:
    #   * Official English Documentation: http://nginx.org/en/docs/
    #   * Official Russian Documentation: http://nginx.org/ru/docs/
    
    user nginx;
    worker_processes auto;
    error_log /var/log/nginx/error.log;
    pid /var/run/nginx.pid;
    
    # Load dynamic modules. See /usr/share/nginx/README.dynamic.
    include /usr/share/nginx/modules/*.conf;
    
    events {
        worker_connections  1024;
    }
    
    
    http {
        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';
    
        access_log  /var/log/nginx/access.log  main;
    
        sendfile            on;
        tcp_nopush          on;
        tcp_nodelay         on;
        keepalive_timeout   65;
        types_hash_max_size 2048;
    
        include             /etc/nginx/mime.types;
        default_type        application/octet-stream;
    
        # Load modular configuration files from the /etc/nginx/conf.d directory.
        # See http://nginx.org/en/docs/ngx_core_module.html#include
        # for more information.
        include /etc/nginx/conf.d/*.conf;
        ###以下为新增内容
        server {
            listen       8090;
            server_name  localhost;
    
            charset UTF-8;
    
            access_log  /var/log/nginx/demosite_access.log;
            error_log /var/log/nginx/demosite_error.log;
    
            client_max_body_size 75M;
    
            location / {
                    include uwsgi_params;
                    uwsgi_pass 127.0.0.1:8080;
                    uwsgi_read_timeout 2;
            }
    
            #location / {
            #    root   html;
            #    index  index.html index.htm;
            #}
            #新添加的location
            #location / {
                #将所有的参数转到uwsgi下
             #   include uwsgi_params;
                #uwsgi的ip与端口
             #   uwsgi_pass 127.0.0.1:8080;
            #}
    
            location /static/ {
                    expires 30d;
                    autoindex on;
                    add_header Cache-Control private;
                    alias /root/test/demosite/static/;
            }
            #error_page  404              /404.html;
          ###以上为新增内容
            }
    }
    

    启动uwsgi:

    uwsgi --ini demosite_uwsgi.ini 
    

    启动nginx:

    service nginx restart
    

    访问:http://140.146.35.85:8090/

    相关文章

      网友评论

          本文标题:nginx + uwsgi部署django

          本文链接:https://www.haomeiwen.com/subject/jhydcctx.html