Django在多个服务器中

时间:2017-05-15 14:28:41

标签: django django-urls

我正在尝试设置django服务器,我希望admin.example.com/app_name中的管理页面,api.example.com/app_name中的api端点和www.example.com/app_name中的普通页面。我试图通过nginx来做,但内部链接搞砸了,我有重定向。我在django甚至可以尝试什么?

1 个答案:

答案 0 :(得分:0)

这是快速而又脏的nginx设置,可以处理我猜的所有要求

如果它不起作用,让我知道/var/log/nginx/error.log和access.log中的错误

upstream django {
    server 127.0.0.1:9001; 
}
#main server
server {
    location /admin {
    deny all;
    }
   location /static {
       alias /var/www/static;
    }
 location / {
        uwsgi_pass  django;
        include         uwsgi_params; # the uwsgi_params file you installed
    }
}
#your api server
server {
server api.example.com
    location /admin {
    deny all;
    }
       location /static {
       alias /var/www/static;
    }
 location / {
        uwsgi_pass  django;
        include         uwsgi_params; # the uwsgi_params file you installed
    }
}
server {
    server_name admin.example.com; 
    location /static {
       alias /var/www/static;
    }
    location /admin {
        uwsgi_pass  django;
        include         uwsgi_params; # the uwsgi_params file you installed
    }
    location / {
    deny all;
    }
}