gpt4 book ai didi

amazon-web-services - 是否可以为 AWS 上的每个子域设置单独的 cname 记录

转载 作者:行者123 更新时间:2023-12-04 21:31:21 25 4
gpt4 key购买 nike

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

这可能吗?

在我的托管区域 example.com. , 我已经为 www.example.com 设置了 cname 记录, staging.example.comdemo.example.com每个都有一个指向其各自 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 ,响应是:

    PING example...elasticbeanstalk.com (35.182.128.147): 56 data bytes



    这很棒。但是当我尝试提出实际要求时:
    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:

    几点。
  • 更新了 DirectoryDocumentRoot指向我的应用程序文件实际存储在我的 flask 应用程序服务器上的位置,"/opt/python/current/app" ,之前我复制粘贴了"/var/app/current/" .
  • 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>

    仍然得到相同的结果。

    最佳答案

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

    更改两者的顺序 VHost部分,或添加 ServerName对他们所有人,事情应该开始工作(可能需要重新启动 EB 应用程序)。

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

    关于amazon-web-services - 是否可以为 AWS 上的每个子域设置单独的 cname 记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50206692/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com