使用nginx将子域指向子目录(nginx + https + gunicorn + django)

时间:2016-05-10 13:48:21

标签: django nginx https gunicorn subdomain

我有https://testsite.com正在研究django + gunicorn + nginx + https。

我的nginx conf(一切都很好):

server {
    listen 80;
    server_name testsite.com;
    access_log off;
    return 301 https://$server_name$request_uri;
}

server {

    listen 443 ssl;
    server_name *.testsite.com;
    proxy_set_header X-Forwarded-Protocol $scheme;

    # lots of sll staff

    location / {
        # point to gunicorn
        proxy_pass http://176.112.198.254:8000/;
    }
}

我需要在指向子目录的子域上实现城市(exept main_city)。

所以我需要这样的网址:

https://testsite.com/some_url/应指向https://testsite.com/main_city/some_url/ https://city1.testsite.com/some_url/应该指向https://testsite.com/city1/some_url/ https://city2.testsite.com/some_url/应指向https://testsite.com/city2/some_url/

我该怎么做?

大帮忙!

1 个答案:

答案 0 :(得分:1)

您必须定义upstrem指令。目前,您的nginx无法代理您的Web应用程序。

http://nginx.org/en/docs/http/ngx_http_upstream_module.html

upstream backend {
    server backend1.example.com       weight=5;
    server backend2.example.com:8080;
    server unix:/tmp/backend3;

    server backup1.example.com:8080   backup;
    server backup2.example.com:8080   backup;
}

server {
    location / {
        proxy_pass http://backend;
    }
}