【发布时间】:2018-10-16 19:35:37
【问题描述】:
我想要 www.example.com、staging.example.com 和 demo.example.com,其中每个映射到 Elastic Beanstalk 上同一应用程序的单独环境。
这可能吗?
在 example.com. 的托管区域上,我为 www.example.com、staging.example.com 和 demo.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:
几点。
-
更新了
Directory和DocumentRoot以指向我的应用程序文件在我的烧瓶应用程序"/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>
仍然得到相同的结果。
【问题讨论】:
-
DNS 更改可能需要一段时间才能传播。您应该使用
nslookup并使用 AWS 提供的 DNS 服务器配置它 -
每次阅读该帖子我都会更新。
标签: amazon-web-services amazon-elastic-beanstalk amazon-route53