在 Ubuntu 上使用 DJANGO 服务 NGINX

Serving NGINX with DJANGO on Ubuntu

我正尝试在 Nginx 服务器上 运行 我的 django(1.8) 项目,因为它要快得多。我可以 运行 通过使用 uwsgi --ini 命令来设置套接字。所以我想做的是运行宁NGINX一个人想要运行我的django项目,有什么办法吗? uwsgi 创建的套接字会在 uwsgi --ini 命令结束时自动删除。

NGINX config and .ini ia as shown below :

# mysite_nginx.conf

# the upstream component nginx needs to connect to
upstream django {

     server unix:///var/www/html/vir/crum/crumbs.sock;

}

    # configuration of the server
    server {
        # the port your site will be served on
        listen      8000;
        # the domain name it will serve for
        server_name .localhost.com; 
        charset     utf-8;


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

        # Django media
        location /media  {
            alias /var/www/html/alteryx_vir/crum/media;  
        }

        location /static {
            alias /var/www/html/vir/crum/static;  

        }

        # Finally, send all non-media requests to the Django server.
        location / {
            uwsgi_pass  django;

            /var/www/html/vir/crum/uwsgi_params; 
        }
    }

    >>> uwsgi.ini file :

    # mysite_uwsgi.ini file
    [uwsgi]

    # Django-related settings
    # the base directory (full path)
    chdir           = /var/www/html/vir/crumb/
    # Django's wsgi file
    module          = crum.wsgi
    # the virtualenv (/alteryx_vir/)
    home            = /var/www/html/alteryx_vir/
    # process-related settings
    # master
    master          = true
    # maximum number of worker processes
    processes       = 10
    # the socket (use the full path to be safe
    socket          = 
    /var/www/html/alteryx_vir/crum/crum.sock
    #socket           = var/run/uwsgi/crum.sock


    # ... with appropriate permissions - may be needed
    chmod-socket    = 666
    # clear environment on exit
    vacuum          = true

在此先感谢您的帮助。

你问的没有意义。套接字用于 nginx 和 uWSGI 之间的通信。如果 uWSGI 不是 运行,套接字的另一端将没有任何东西,也没有任何东西为您的应用服务。

你需要 nginx 和 uWSGI。

是的,Atlas 我可以使用 UWSGI EMPEROR 模式自动执行所有操作。 现在所有命令都可以自动执行,您需要做的就是启动 NGINX 服务器。

皇帝模式:

编辑 /etc/rc.local 并添加:

/usr/local/bin/uwsgi --emperor /etc/uwsgi/vassals --uid www-data --gid www-data --daemonize /var/log/uwsgi-emperor.log