【问题标题】:Point subdomains to subdirectories with nginx (nginx + https + gunicorn + django)使用 nginx 将子域指向子目录(nginx + https + gunicorn + django)
【发布时间】:2016-09-05 13:07:31
【问题描述】:

我有 https://testsite.com 在 django + gunicorn + nginx + https 上工作。

我的 nginx 配置(一切正常):

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/;
    }
}

我需要在指向子目录的子域上实现城市(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/

我该怎么做?

非常感谢帮助!

【问题讨论】:

  • Django multi tenancy的可能重复
  • @Sayse,没有关于 ssl 和 https
  • 我更多地指的是该答案中包含的链接,该链接托管了为帮助支持此问题而制作的所有可能的软件包

标签: django nginx https gunicorn subdomain


【解决方案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;
    }
}

【讨论】:

    猜你喜欢
    • 2016-07-21
    • 2013-06-12
    • 2011-12-15
    • 2015-08-26
    • 2019-04-29
    • 1970-01-01
    • 1970-01-01
    • 2015-08-26
    • 2016-01-09
    相关资源
    最近更新 更多