2017-11-25 189 views
0

我試圖在Nginx服務器上運行我的django(1.8)項目,因爲它速度更快。我可以通過使用uwsgi --ini命令來設置套接字。所以我想要做的就是單獨運行NGINX想運行我的django項目,有沒有辦法做到這一點?那麼當uwsgi --ini命令結束時,由uwsgi創建的套接字將自動移除。在Ubuntu上使用DJANGO服務NGINX

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 

在此先感謝您的幫助。

回答

0

是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 
0

你問的沒有意義。套接字用於nginx和uWSGI之間的通信。如果uWSGI沒有運行,那麼套接字的另一端沒有任何內容,並且沒有爲您的應用程序提供服務。

您需要nginx和uWSGI。

+0

是啊,我是小姐,然後引導thanx您的信息先生。 @丹尼爾,我怎麼能自動化。我不想運行一些命令來啓動uwsgi。希望你得到了我的觀點 –

+0

與任何服務器進程(包括nginx本身)一樣,您可以使用發行版的進程管理器 - 例如systemd或upstart - 或supervisord之類的東西。 –

相關問題