【问题标题】:Is it possible to have a separate cname record for each subdomain on AWS是否可以为 AWS 上的每个子域设置单独的 cname 记录
【发布时间】:2018-10-16 19:35:37
【问题描述】:

我想要 www.example.comstaging.example.comdemo.example.com,其中每个映射到 Elastic Beanstalk 上同一应用程序的单独环境。

这可能吗?

example.com. 的托管区域上,我为 www.example.comstaging.example.comdemo.example.com 设置了 cname 记录,每个记录都有一个指向其各自 EB url 的值。

我设置的第一个www.example.com 工作并且请求到达环境。但是当我尝试使用ping staging.example.com 联系其他人时,结果是ping: cannot resolve staging.example.com: Unknown host

  • 购买的域名和托管在 Route 53 上的区域
  • 在 AWS 证书管理器上颁发的证书
  • 我已在每个负载均衡器上以相同的方式设置证书
  • 第一个,www.example.com 工作正常
  • 其他人没有
  • 除非不可能,否则我不确定我在这里缺少什么

这是否可行?

注意:我已将我的实际域替换为 example.com

更新 1:

我可能越来越近了,但它还没有工作,它正在返回You don't have permission to access /user

通过此链接,https://serverfault.com/questions/407961/setting-up-subdomains-within-amazon-aws-elastic-beanstalk

我补充说:

files:
  "/etc/httpd/conf.d/vhost.conf":
    mode: "000644"
    owner: root
    group: root
    encoding: plain
    content: |
      NameVirtualHost *:80

      <VirtualHost *:80>
        DocumentRoot "/var/app/current/"
         <Directory "/var/app/current/">
          Options Indexes FollowSymLinks MultiViews
          AllowOverride All
          Require all granted
         </Directory>
      </VirtualHost>

      <VirtualHost *:80>
       ServerName staging.example.com
       DocumentRoot "/var/app/current/your-new-webroot"
        <Directory "/var/app/current/your-new-webroot">
         Options Indexes FollowSymLinks MultiViews
         AllowOverride All
         Require all granted
        </Directory>
      </VirtualHost>

现在当我运行ping staging.example.com 时,响应是:

平 例如...elasticbeanstalk.com (35.182.128.147):56 个数据字节

这很棒。但是当我尝试提出我的实际要求时:

curl -X POST -H "Content-Type: application/json" 
-H "Authorization: Bearer ..." -d '{}' https://staging.example.com/user

回复是:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /user
on this server.<br />
</p>
</body></html>

更新 2:

我已经重新排序了我的 VirtualHosts 并添加了 ServerName,所以它现在看起来像这样:

files:
  "/etc/httpd/conf.d/vhost.conf":
    mode: "000644"
    owner: root
    group: root
    encoding: plain
    content: |
      NameVirtualHost *:80

      <VirtualHost *:80>
       ServerName staging.example.com
       DocumentRoot "/var/app/current/your-new-webroot"
        <Directory "/var/app/current/your-new-webroot">
         Options Indexes FollowSymLinks MultiViews
         AllowOverride All
         Require all granted
        </Directory>
      </VirtualHost>

      <VirtualHost *:80>
        ServerName www.example.com
        DocumentRoot "/var/app/current/"
         <Directory "/var/app/current/">
          Options Indexes FollowSymLinks MultiViews
          AllowOverride All
          Require all granted
         </Directory>
      </VirtualHost>

但我仍然从我的POST 请求中得到相同的响应:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /user
on this server.<br />
</p>
</body></html>

另外,根据我的/var/log/httpd/error_log 日志:

AH01630: client denied by server configuration: /var/app

更新 3:

几点。

  1. 更新了 DirectoryDocumentRoot 以指向我的应用程序文件在我的烧瓶应用程序 "/opt/python/current/app" 的服务器上实际存储的位置,之前我复制并粘贴了 "/var/app/current/"

  2. httpd -v检查了我的apache版本。结果是,Server version: Apache/2.4.27 (Amazon) \n Server built: Sep 24 2017 23:19:50

更新文件:

files:
  "/etc/httpd/conf.d/vhost.conf":
    mode: "000644"
    owner: root
    group: root
    encoding: plain
    content: |
      NameVirtualHost *:80

      <VirtualHost *:80>
       ServerName staging.example.com
       DocumentRoot "/opt/python/current/app"
        <Directory "/opt/python/current/app">
         Options Indexes FollowSymLinks MultiViews
         AllowOverride All
         Require all granted
        </Directory>
      </VirtualHost>

      <VirtualHost *:80>
        ServerName www.example.com
        DocumentRoot "/opt/python/current/app"
         <Directory "/opt/python/current/app">
          Options Indexes FollowSymLinks MultiViews
          AllowOverride All
          Require all granted
         </Directory>
      </VirtualHost>

仍然得到相同的结果。

【问题讨论】:

  • DNS 更改可能需要一段时间才能传播。您应该使用 nslookup 并使用 AWS 提供的 DNS 服务器配置它
  • 每次阅读该帖子我都会更新。

标签: amazon-web-services amazon-elastic-beanstalk amazon-route53


【解决方案1】:

ping staging.example.com 有效,因为您的 CNAME 已正确解析。但是,VirtualHost 指令以线性方式应用。由于您的第一个 VHost 部分不包含 ServerName,因此它默认应用于所有请求。

更改两个VHost 部分的顺序,或将ServerName 添加到所有部分,一切应该开始工作(可能需要重新启动EB 应用程序)。

你也可以检查机器本身的日志文件,如果还有其他原因导致 403 错误。

【讨论】:

  • > 您也可以检查机器本身的日志文件,如果还有其他原因导致 403 错误。 @tim_xyz
  • 我发布了这些日志,/var/log/httpd/error_log。还有其他我应该看的吗?抱歉,我对基础架构配置不太熟悉。
  • 好的,可能是简单的 apache 版本不匹配。 @tim_xyz 您能否确认您是否确实在使用 apache 2.4 或更高版本?如果没有,请检查此stackoverflow.com/a/19588786/1190388
  • 我检查了 apache 版本。它的Apache/2.4.27。将我的 vhost 文件更新为正确的 Directory "/opt/python/current/app",并查看了该 SO 帖子。还有什么我想尝试的吗?
猜你喜欢
  • 2023-03-20
  • 1970-01-01
  • 2017-09-14
  • 2013-04-17
  • 2015-01-01
  • 2018-04-23
  • 2013-01-23
  • 2013-03-21
  • 2018-06-11
相关资源
最近更新 更多