映射到自定义域仍然显示 *.scapp.io

Map to custom domain still displays *.scapp.io

我只是按照程序将单个域映射到我的自定义域:

  1. 在 ORGS
  2. 中创建域 mydomain.com
  3. 在 SPACES
  4. 中创建路线 myapp.mydomain.com
  5. 将我的应用映射到 SPACES
  6. 中的 myapp.scapp.iomyapp.mydomain.com
  7. 使用名称 myapp 和目标 mapapp.scapp.iomydomain.com 添加 CNAME DNS 条目(我使用的是亚马逊路由 53)

映射有效,我可以用myapp.mydomain.com访问myapp,但地址仍然显示myapp.scapp.io

如何使映射透明并在地址栏中显示myapp.mydomain.com

更新:

我设法让它在亚马逊 53 号公路上运行:

  1. 在 ORGS
  2. 中创建域 mydomain.com
  3. 在 SPACES
  4. 中创建路线 myapp.mydomain.com
  5. 将我的应用映射到 SPACES

  6. 中的 myapp.scapp.iomyapp.mydomain.com
  7. mydomain.com 添加名称 myapp-cname 和目标 myapp.scapp.io

  8. 的 CNAME DNS 条目
  9. mydomain.com 添加名称为 myapp 的 CNAME DNS 条目,启用 Alias 和目标 myapp-cname.mydomain.com

它按预期在地址栏中显示 myapp.mydomain.com,但我怀疑这是正确的做法。

@UPDATE 问题出在我的 meteor 应用程序中,它没有正确地强制请求 https。我使用的是 force-ssl 包,但正如 README 中所说:

Meteor bundles (i.e. meteor build) do not include an HTTPS server or certificate. A proxy server that terminates SSL in front of a Meteor bundle must set the x-forwarded-proto or forwarded (RFC 7239) header for this package to work.

因此,我使用带有自定义 nginx.conf.

的静态文件应用程序

我使用 staticfile-buildpack 创建了一个静态文件应用程序,将我的私有域添加到 manifest.yml 中的 routes,并将环境变量 FORCE_HTTPS 设置为 true:

applications:
  - name: my-nginx
    memory: 128M
    instances: 1
    buildpack: https://github.com/cloudfoundry/staticfile-buildpack.git
    routes:
      - route: 'app1.mydomain.com'
      - route: 'app2.mydomain.com'
      - route: 'app1.subdomain.mydomain.com'
      - route: 'app2.subdomain.mydomain.com'
      - route: 'app3.mydomain.com'
    env:
      FORCE_HTTPS: true

下一步是为我的每个私有域创建带有 server{...} 块的自定义 nginx.conf,并在相应的 scapp.io 域上使用 proxy_pass(这里有两个私有域):

worker_processes 1;
daemon off;

error_log <%= ENV["APP_ROOT"] %>/nginx/logs/error.log;
events { worker_connections 1024; }

http {
  charset utf-8;
  log_format cloudfoundry '$http_x_forwarded_for - $http_referer - [$time_local] "$request" $status $body_bytes_sent';
  access_log <%= ENV["APP_ROOT"] %>/nginx/logs/access.log cloudfoundry;
  default_type application/octet-stream;
  include mime.types;
  sendfile on;

  gzip on;
  gzip_disable "msie6";
  gzip_comp_level 6;
  gzip_min_length 1100;
  gzip_buffers 16 8k;
  gzip_proxied any;
  gunzip on;
  gzip_static always;
  gzip_types text/plain text/css text/js text/xml text/javascript application/javascript application/x-javascript application/json application/xml application/xml+rss;
  gzip_vary on;

  tcp_nopush on;
  keepalive_timeout 30;
  port_in_redirect off; # Ensure that redirects don't include the internal container PORT - <%= ENV["PORT"] %>
  server_tokens off;

  server {
    listen <%= ENV["PORT"] %>;
    server_name app1.mydomain.com;

    # Redirects to https if the environment variable "FORCE_HTTPS" is set to true
    <% if ENV["FORCE_HTTPS"] %>
     if ($http_x_forwarded_proto != "https") {
       return 301 https://$host$request_uri;
     }
    <% end %>

    location / {
      proxy_pass  https://app1.scapp.io/;
    }
  }

  server {
    listen <%= ENV["PORT"] %>;
    server_name app2.mydomain.com;

    <% if ENV["FORCE_HTTPS"] %>
     if ($http_x_forwarded_proto != "https") {
       return 301 https://$host$request_uri;
     }
    <% end %>

    location / {
      proxy_pass  http://app2.scapp.io/;
    }  
  }
}

接下来的步骤是常规步骤:

  • 在正确的 ORG 中创建域 mydomain.com,并在正确的 SPACE 中创建我的每个私有路由。
  • 在 swisscomdev 控制台中为我的每个私有域创建 SSL 证书。
  • 使用名称 * 和目标 my-nginx.scapp.iomydomain.com 创建 CNAME DNS 条目(swisscom 为我的静态文件应用程序自动分配的 scapp.io 路由)。

最后,我用 cf push 推送了该应用程序,它非常有效!