我可以使用其他端口运行3个uwsgi服务吗 [英] Can I run 3 uwsgi service using different port

查看:129
本文介绍了我可以使用其他端口运行3个uwsgi服务吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在同一服务器上有3个python django应用程序.我想使用不同的端口运行每个服务.

I have 3 python django application on same server. And I want to run each service using different port.

ex)最终用户为80服务提供商8001服务人员使用8002

ex) 80 for end user 8001 for service provider 8002 for service operator

但是我不知道该怎么做.

But I have no idea how can I do this.

现在,一个uwsgi服务正在使用systemctl运行.

Now, one uwsgi service is running using systemctl.

这是我的uwsgi.service.

This is my 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.

And uwsgi.ini is the following.

[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/uwsgi-@(exec://date +%Y-%m-%d).log
log-reopen = true

我的nginx设置如下.

And my nginx setting is the following.

# 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配置文件.

I want to know how can I make settings in order to launch some uwsgi service and how to setting nginx config file.

你能给我个建议吗?

谢谢.

推荐答案

uwsgi_p1.ini for my_project1

uwsgi_p1.ini for 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

my_project1的nginx_p1.conf

nginx_p1.conf for 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 for my_project2

uwsgi_p2.ini for 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

my_project2的nginx_p2.conf

nginx_p2.conf for 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;
}
}

以此类推...

这篇关于我可以使用其他端口运行3个uwsgi服务吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆