【问题标题】:Subdomain Proxy Pass using Cloudflare and nginx使用 Cloudflare 和 nginx 的子域代理通行证
【发布时间】:2021-02-08 01:07:01
【问题描述】:

我有一个由 Cloudflare 的免费工具管理的域。我有一个要添加的名为“test”的子域,但我希望它指向在我的服务器上运行的第二个网络服务器,端口为 8183。在 Cloudflare DNS 门户中,我有一个“test.example.com”的 A 记录,它指向到我的网络服务器的 IP 地址,该地址也被代理以隐藏我的网络服务器的实际 IP 地址。所有流量都通过 HTTPS 路由,证书也由 Cloudflare 提供。

我的 nginx default.conf:

# Redirect all traffic to HTTPS/443/SSL
server {
    server_name example.com *.example.com;

    listen 80;

    return 301 https://$host$request_uri;
}

# example.com
server {
    server_name example.com;

    listen 443 ssl;

    index index.php index.html;

    ssl_certificate /etc/ssl/origincert.pem;
    ssl_certificate_key /etc/ssl/privkey.key;

    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /website;

    location ~ \.php$ {
        autoindex on;
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

# test.example.com -> proxy pass to 8183
server {
    server_name test.example.com;

    listen 443 ssl;

    ssl_certificate /etc/ssl/origincert.pem;
    ssl_certificate_key /etc/ssl/privkey.key;

    location / {
        proxy_pass http://MY_SERVER_IP_ADDRESS:8183;
    }
}

但是,当我导航到 https://test.example.comhttp 时,我只是重新路由到 https://example.com。我在我的服务器上安装了一个原始服务器证书,它安装并使用了example.com, *.example.com, and test.example.com

【问题讨论】:

    标签: nginx cloudflare nginx-reverse-proxy


    【解决方案1】:

    这可能是 DNS 记录的问题。检查它们并确保没有像 *.example.com -> example.com 这样的记录 确保test 子域直接指向您服务器的IP 地址,与example.com 相同。

    所以如果你有 example.com -> 1.2.3.4 确保你也有 test.example.com -> 1.2.3.4. 而不是 test.example.com -> example.com

    【讨论】:

      猜你喜欢
      • 2017-07-25
      • 2020-03-24
      • 2019-07-01
      • 1970-01-01
      • 2016-03-16
      • 1970-01-01
      • 2019-05-08
      • 2014-12-04
      • 1970-01-01
      相关资源
      最近更新 更多