How to forward http request to https in Amazon Route53?

我只是一个虾纸丫 提交于 2019-12-18 12:49:12

问题


I have a subdomain in Amazon Route53. Let's say secure.example.com

If requests come like https://secure.example.com it is ok but I would like to force http requests to come through https. When user types http://secure.example.com it needs to be forwarded to https://secure.example.com.

Is there a domain level redirecting/forwarding requests coming through http to https in Amazon Route53?


回答1:


No, there is no way to do this -- because it's not a DNS function to force any particular protocol, or to push values from one protocol to another. You can do this easily enough at the web server level, either in Apache, or IIS, or NGINX.

In any of those cases, the A or CNAME value pointing a specific record to a specific address (whether an IP or another host name) is the same, it's just going to connect via port 80 or port 443.

In Apache, you can simply use a rewrite (enable mod_rewrite first):

RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://www.host.com/$1 [R]



回答2:


Just a quick update for this question. Whilst in answer to your question no, you can't use route 53 to force HTTPS, this would lead some people to believe that forcing https on AWS hosting wasn't possible.

You can create a SSL certificate in Certificate Manager(or import your own), host your website where ever(S3/EC2), you then need to setup a CloudFront distribution for your site and import your SSL certificate, you can then use the option Redirect HTTP to HTTPS via the behavior tab in the CloudFront console.




回答3:


2019 +

The @Jamaurice Holt solution led me to the way but was a bit short

This solution only work with application load balancer, not classic load balancer.

On the console go to EC2 > Load balancers > your load balancer > listeners

Here you should have 2 rules: HTTP : 80 and HTTPS : 443

You just have to:

  • edit the HTTP : 80 rule

  • remove the forward rule and add a redirect rule to port 443

  • save and you should see something like:




回答4:


I accomplished it using a (ELB) application load balancer and redirecting the traffic to port 443 in the ELB edit section. Of course I'm using an ec2 instance to host my application and website.



来源:https://stackoverflow.com/questions/12176969/how-to-forward-http-request-to-https-in-amazon-route53

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!