How to forward http request to https in Amazon Route53?

前端 未结 4 2002
一向
一向 2020-12-29 04:09

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

相关标签:
4条回答
  • 2020-12-29 04:39

    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]
    
    0 讨论(0)
  • 2020-12-29 04:39

    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.

    0 讨论(0)
  • 2020-12-29 04:52

    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.

    0 讨论(0)
  • 2020-12-29 04:55

    2019 +

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

    Classic Load Balancer

    This solution only work with application load balancer, not classic load balancer, but you can migrate to use a more recent app balancer in EC2 > Load balancers > your load balancer > migrate

    Application 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:

    0 讨论(0)
提交回复
热议问题