问题
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.
I have an API hosted on EB and the Squarespace site makes requests to that 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
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
EDIT -
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....
- 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 be created when deploying the Docker image. Allow HTTPS inbound traffic on 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 to make 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();
});
}
}
回答1:
All this was caused by the SSL cert registered to the wrong domain. CORS is functioning as it should.
来源:https://stackoverflow.com/questions/60860216/use-godaddy-domain-name-instead-of-default-elastic-beanstalk-url