【问题标题】:Serving NGINX with DJANGO on Ubuntu在 Ubuntu 上使用 DJANGO 服务 NGINX
【发布时间】:2017-11-25 11:03:53
【问题描述】:

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

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

提前感谢您的帮助。

【问题讨论】:

    标签: django nginx uwsgi


    【解决方案1】:

    你问的没有意义。套接字用于 nginx 和 uWSGI 之间的通信。如果 uWSGI 未运行,则套接字的另一端将没有任何内容,也没有任何内容为您的应用程序提供服务。

    你需要 nginx 和 uWSGI。

    【讨论】:

    • 是的,我错过了指导,然后谢谢您的信息先生。 @Daniel 那么我该如何自动化。我不想运行一些命令来启动 uwsgi。希望你明白我的意思
    • 像任何服务器进程(包括 nginx 本身)一样,您使用发行版的进程管理器 - 例如 systemd 或 upstart - 或类似 supervisord 的东西。
    【解决方案2】:

    是的,Atlast 我可以使用 UWSGI EMPEROR 模式自动执行所有操作。 现在所有命令都可以自动化了,您只需启动 NGINX 服务器即可。

    Emperror 模式:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-03-12
      • 2021-09-06
      • 1970-01-01
      • 2021-04-05
      • 2018-08-15
      • 2017-06-05
      • 2017-08-07
      相关资源
      最近更新 更多