如何在Nginx中使用django主机

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

我创建了一个Django应用,其中有两个应用分别名为“ api”和“ consumer”。现在,我想同时为该应用程序使用子域。类似于api.server.comserver.com。我在网上搜索并找到了django主机,因此我在localhost中实现了它,并且可以正常工作。

[之后,我将其部署在AWS EC2实例上,并在Godaddy中创建了子域,并将根域和子域都指向我的实例IP。根域工作正常,但是当我尝试进入api.server.com时,它显示了默认的Welcome to Nginx屏幕。请帮助我解决这个问题。

nginx.conf

server{
    server_name server.com, api.server.com;
    access_log  /var/log/nginx/example.log;

    location /static/ {
        alias /home/path/to/static/;
    }

    location / {
        proxy_pass http://127.0.0.1:8000;
        proxy_set_header Host $server_name;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}
python django nginx subdomain django-hosts
1个回答
0
投票

您不需要,,只需一个简单的空格即可。

server_name server.com  api.server.com;

也可以使用通配符,请参见the documentation

server_name *.server.com;
© www.soinside.com 2019 - 2024. All rights reserved.