我可以在 2 个域但 1 个 ip 上运行 2 个 django 项目吗?

问题描述 投票:0回答:1

我正在尝试使用这两种配置使用 nginx 运行两个 django 项目:

upstream django {
    server unix:///home/hypebeeruser/HypeBeer/HypeBeerProject/HypeBeerProject.sock;
}

# configuration of the server
server {
    server_name hypebeer.com.ua;
    charset     utf-8;
    # max upload size
    client_max_body_size 75M;
    # Django media and static files
    location /media  {
        alias /home/hypebeeruser/HypeBeer/HypeBeerProject/media;
    }
    location /static {
        alias /home/hypebeeruser/HypeBeer/HypeBeerProject/static;
    }
    # Send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django;
        include     /home/hypebeeruser/HypeBeer/HypeBeerProject/uwsgi_params;
    }
}
# the upstream component nginx needs to connect to
upstream django_tobabox {
    server unix:///home/tobabox/TobaBox/TobaBox/TobaBox.sock;
}
# configuration of the server
server {
    listen      80;
    server_name tobabox.com www.tobabox.com;
    charset     utf-8;
    # max upload size
    client_max_body_size 75M;
    # Django media and static files
    location /media  {
        alias /home/tobabox/TobaBox/TobaBox/media;
    }
    location /static {
        alias /home/tobabox/TobaBox/TobaBox/static;
    }
    # Send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django_tobabox;
        include     /home/tobabox/TobaBox/TobaBox/uwsgi_params;
    }
}

我运行

uwsgi --socket HypeBeerProject.sock --module HypeBeerProject.wsgi --chmod-socket=666
并且它运行我的第一个站点,但第二个站点不能使用相同的命令(是的,我更改了 .sock 和 project.wsgi 的名称)。运行正常,没有任何错误,但是还是无法通过域名连接。
我需要购买额外的 IP 还是可以以某种方式对其进行配置,以便一个 IP 上有两个站点和两个域?

django nginx virtualhost
1个回答
0
投票

您可以在单个 IP 上运行多个域。在 Apache 中,您使用 VirtualHost 指令。在 nginx 上,它们被称为服务器块。 Digital Ocean 有一个很好的教程:https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-virtual-hosts-on-ubuntu-16-04

© www.soinside.com 2019 - 2024. All rights reserved.