问题描述
我在Godaddy上购买了一个域名.该网站托管在Squarespace上,因此我不想将请求从 https://example.com 转发到Elastic Bean Stalk上的站点.
I have a domain name bought on Godaddy. The site is hosted on Squarespace, so I don't want to forward requests from https://example.com to a site on Elastic Bean Stalk.
我在EB上托管了一个API,Squarespace网站向该API发出了请求.
I have an API hosted on EB and the Squarespace site makes requests to that API.
我需要做的是更改默认的EB URL https://dataservice-env.example.us-east-2.elasticbeanstalk.com 到 https://example.com/api
What I need to do is change the default EB URL https://dataservice-env.example.us-east-2.elasticbeanstalk.com to https://example.com/api
我在这里几乎是DNS菜鸟.我已经找到了将Godaddy域转发到EB的文章,但这不是我想要做的,这就是我所描述的...
I'm pretty much a DNS noob here. I've found articles to forward godaddy domains to EB, but thats not what I want to do, which is what I think this is describing...
https://stackoverflow.com/a/38225802
编辑-
如果有人尝试做类似的事情(通过一个子域上的HTTPS从一个域向EB发送API请求),这就是我的方法....
If any one else is trying to do something similar (make API requests from one domain to EB over HTTPS on a subdomain) here's how I did it....
- 在Route 53中注册域
- 创建托管区域
- 从GoDaddy导出的区域文件
- 将区域文件导入到Route 53托管区域
- 从AWS Certificate Manager请求证书
- 使用子域api.example.com作为域名值
- 点击在Route 53中创建记录"
- 在Route 53中,点击创建记录"
- 名称:api.css-llc.io
- 类型:A-IPv4地址
- 别名:是
- 别名:EB URL-env.tstuff.us-east-2.elasticbeanstalk.com
- 创建负载均衡器.最重要的是为创建一个监听器 HTTPS这会将请求从端口443转发到端口80,即.net 核心API在端口80上运行
- 侦听器端口:443
- 实例端口:80
- 侦听器协议:HTTPS
- 实例协议:HTTP
- 使用上面创建的api.example.com证书
- 将此负载均衡器添加到EC2实例. EC2实例应为在部署Docker映像时创建.允许HTTPS入站流量负载均衡器创建的两个安全组上
- 将CORS支持添加到API Server. .net Core CORS的以下示例
这应该返回正确的响应头,并且应该能够通过HTTPS从example.com向api.example.com发出请求
- Register a domain in Route 53
- Create a Hosted Zone
- Exported zone file from GoDaddy
- Import Zone File to Route 53 Hosted Zone
- Request a certificate from AWS Certificate Manager
- Use subdomain api.example.com for domain name value
- Click ‘Create Record in Route 53'
- In Route 53 click 'Create Record'
- Name: api.css-llc.io
- Type: A-IPv4 Address
- Alias: Yes
- Alias Target: EB URL - env.tstuff.us-east-2.elasticbeanstalk.com
- Create Load Balancer. Most important is to create a listener for HTTPS This will forward requests from port 443 to port 80, the .net Core API is running on port 80
- Listener Port: 443
- Instance Port: 80
- Listener Protocol: HTTPS
- Instance Protcol: HTTP
- Use api.example.com cert created above
- Add this load balancer to EC2 Instance. The EC2 instance should becreated when deploying the Docker image. Allow HTTPS inbound trafficon the two security groups created by the load balancer
- Add CORS support to API Server. Example below for .net Core CORS
This should return the correct response headers and should be able tomake requests from example.com to api.example.com via HTTPS
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseCors(builder => builder
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader());
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
推荐答案
所有这些都是由注册到错误域的SSL证书引起的. CORS发挥了应有的作用.
All this was caused by the SSL cert registered to the wrong domain. CORS is functioning as it should.
这篇关于使用Godaddy域名代替默认的Elastic BeanStalk URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!