【问题标题】:How to configure NGINX & uwsgi to support several TLDs with one app如何配置 NGINX 和 uwsgi 以通过一个应用程序支持多个 TLD
【发布时间】:2020-02-28 00:55:38
【问题描述】:

我正在使用 Python & uwsgi & NGINX 配置,并且我的域有一个应用程序和多个 TLD,例如:

mydomain.com

blog.mydomain.com

news.mydomain.com

我当前的 NGINX 配置:

server {
    listen 80;
    listen 443 ssl;

    server_name mydomain.com www.mydomain.com *.mydomain.com;

    location / {
        include uwsgi_params;
        uwsgi_pass unix:/app/mydomain/mydomain.sock;
    }
}

期望的行为:

我想在我的应用程序中定义额外的端点“/blog_tld”,并将这个端点与域名 blog.mydomain.com 匹配。

当用户打开 blog.mydomain.com 时,他/她应该会看到来自 mydomain.com/blog_tld 的内容,但浏览器中的地址应保持为 blog.mydomain.com

我不想为每个 TLD 创建单独的应用程序和 uwsgi 服务。我想使用一个应用程序和一个 uwsgi 服务,但针对不同的 TLD 显示不同的内容。

我该怎么做?

【问题讨论】:

标签: nginx uwsgi nginx-config


【解决方案1】:

类似的东西

server {
    listen 80;
    listen 443 ssl;

    ssl_...
    ...

    server_name blog.mydomain.com;

    location / {
        include uwsgi_params;
        uwsgi_pass http://127.0.0.1:<port>/blog_tld
    }
}

server {
    listen 80 default_server;
    listen 443 ssl default_server;

    ssl_...
    ...

    server_name mydomain.com *.mydomain.com;

    location / {
        include uwsgi_params;
        uwsgi_pass http://127.0.0.1:<port>;
    }
}

【讨论】:

  • 也试过这种方式,但是nginx不能接受配置:uwsgi_pass http://127.0.0.1:&lt;port&gt;/blog_tld
  • 将此替换为端口号(应为 9000 或其他)。如果仍然无法正常工作,请将行替换为 proxy_pass http://127.0.0.1:&lt;port&gt;/blog_tld;(或 9000)
猜你喜欢
  • 1970-01-01
  • 2015-07-18
  • 1970-01-01
  • 2015-07-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-04
相关资源
最近更新 更多