2017-08-24 20 views
0

我在同一臺服務器上有3個python django應用程序。我想用不同的端口來運行每個服務。我可以使用不同的端口運行3個uwsgi服務

前) 80終端用戶 8001爲服務提供商 8002服務運營商

但我不知道我怎麼能做到這一點。

現在,一個uwsgi服務正在使用systemctl運行。

這是我的uwsgi.service。

# uwsgi.service 
[Unit] 
Description=uWSGI 
After=syslog.target 

[Service] 
ExecStartPre=/bin/bash -c 'mkdir -p /var/run/uwsgi; chown root:ubuntu 
/var/run/uwsgi; chmod g+w /var/run/uwsgi;' 
ExecStart=/bin/bash -c 'source /var/www/html/remosys/bin/activate; uwsgi --ini /var/www/html/remosys/uwsgi.ini' 
#Restart=always 
Restart=on-failure 
KillSignal=SIGQUIT 
Type=notify 
StandardError=syslog 
NotifyAccess=all 

[Install] 
WantedBy=multi-user.target 

而uwsgi.ini如下。

[uwsgi] 
uid = ubuntu 
gid = ubuntu 

# Django-related settings 
# the base directory (full path) 
chdir = /var/www/html/remosys/remoshin 

# Django's wsgi file 
module = remoshin.wsgi 

# the virtualenv (full path) 
home = /var/www/html/remosys 


# process-related settings 
# master 
master = true 

# maximum number of worker processes 
processes = 2 

threads = 1 

# the socket (use the full path to be safe 
socket = /var/run/uwsgi/master.sock 

pidfile = /var/run/uwsgi/master.pid 

# ... with appropriate permissions - may be needed 
chmod-socket = 666 

# clear environment on exit 
vacuum = true 

thunder-lock = true 

max-requests = 6000 
max-requests-delta = 300 

# log 
logto = /var/log/uwsgi/uwsgi.log 
deamonize = /var/log/uwsgi/[email protected](exec://date +%Y-%m-%d).log 
log-reopen = true 

而我的nginx設置如下。

# the upstream component nginx needs to connect to 
upstream django { 
    # for a file socket 
    server unix:///var/run/uwsgi/master.sock; 
} 

# configuration of the server 
server { 
    # the port your site will be served on 
    listen  80; 
    # the domain name it will serve for 
    # substitute your machine's IP address or FQDN 
    server_name localhost 
    charset  utf-8; 

    location /clinic { 
     # your Django project's static files - amend as required 
     alias /home/ubuntu/public_html/clinic; 
    } 
    # max upload size 
    # Django media 
    location /static { 
     # your Django project's static files - amend as required 
     alias /home/ubuntu/remosys/remoshin/apiv1/static; 
    } 

    # Finally, send all non-media requests to the Django server. 
    location/{ 
     uwsgi_pass django; 
     # the uwsgi_params file you installed 
     include  /var/www/html/remosys/uwsgi_params; 
} 

}

我想知道我怎麼能以推出一些uwsgi服務,以及如何設置nginx的配置文件進行設置。

你能給我一個建議嗎?

在此先感謝。

回答

1

uwsgi_p1.ini爲my_project1

[uwsgi] 
chdir = /root/my_workplace/my_project1 
module = my_project1.wsgi 
virtualenv = /root/my_workplace/virtual/my_project1 
processes = 2 
socket = 127.0.0.1:10001 # **pay attention to this port** 
vacuum = true 
master = true 

nginx_p1.conf爲my_project1

server { 
listen  8888; # use different server_name or listenport 
charset  utf-8; 
client_max_body_size 75M; 

server_name project1.mydomain.com; # use different server_name or listenport 

location/{ 
    uwsgi_pass 127.0.0.1:10001; # pay attention to here 
    include  uwsgi_params; 
} 
} 

====================== ========

uwsgi_p2.ini爲my_project2

[uwsgi] 
chdir = /root/my_workplace/my_project2 
module = my_project2.wsgi 
virtualenv = /root/my_workplace/virtual/project2 
processes = 2 
socket = 127.0.0.1:10002 
vacuum = true 
master = true 

納克inx_p2.conf爲my_project2

server { 
listen  8889; 
charset  utf-8; 
client_max_body_size 75M; 

server_name project2.mydomain.com; 

location/{ 
    uwsgi_pass 127.0.0.1:10002; 
    include  uwsgi_params; 
} 
} 

等等...

+0

感謝您的建議。我有更多的問題。你如何啓動uwsgi服務?我嘗試了'sudo systemctl uwsgi --ini uwsgi_1.ini'和'sudo systemctl uwsgi --ini uwsgi_2.ini'。但是當我嘗試啓動第二個命令時,我收到了重複的錯誤消息。 –

+0

我使用[supervisor](http://www.supervisord.org/)。這是管理django-uwsgi進程的常用方法。 –

+0

非常感謝。我會嘗試。 –

相關問題