本文介绍了使用AWS Elastic beantalk将非www重定向到www的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Elastic Beanstalk,并且已经按照说明使用Express Web服务器部署应用程序,如下所示: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_nodejs_express.html

I'm using Elastic Beanstalk and I've followed the instructions to deploy my app using the express web server as follow:http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_nodejs_express.html

此设置使用nginx和路由53.

This setup uses nginx and route 53.

一切正常,但现在我正尝试从非www/non-https URL重定向到" https: //www.domain.com "(始终与www一起为https).

Everything works well, but now I'm trying to redirect from non-www/non-https URLs to "https://www.domain.com" (always https with www).

我已经看到了不同的解决方案,这些解决方案要么不起作用,要么看上去很笨拙.从aws console执行此操作的正确方法是什么?

I've seen different solutions out there that either aren't working or seem hacky. What's the proper way to do this from the aws console?

非常感谢!

推荐答案

您可以设置将裸域重定向到www的S3存储桶.在这里解释.

You can setup a S3 bucket that redirects naked domain to www. It is explained here.

http://docs .aws.amazon.com/AmazonS3/latest/dev/website-hosting-custom-domain-walkthrough.html

您可以使用Cloudfront将http重定向到https.您可以在此处阅读更多信息.

You can redirect http to https by using Cloudfront. You can read more information here.

http://docs.aws.amazon.com /AmazonCloudFront/latest/DeveloperGuide/using-https.html

您也可以在EC2实例上设置Web服务器以进行重定向,但是这也需要设置SSL证书.让AWS使用Cloudfront进行处理更加容易.

You can setup the webserver on your EC2 instances to redirect as well, but that requires that you setup up your SSL certificate as well. It is easier to let AWS handle that with Cloudfront.

您可能正在使用Apache,所以会是这样.

You are probably using Apache so it would be something like this.

NameVirtualHost *:80
<VirtualHost *:80>
   ServerName mysite.example.com
   DocumentRoot /usr/local/apache2/htdocs 
   Redirect permanent / https://mysite.example.com/
</VirtualHost>

<VirtualHost _default_:443>
   ServerName mysite.example.com
   DocumentRoot /app/directory/
   SSLEngine On
   # etc...
</VirtualHost>

然后在部署脚本中使用LetsEncrypt设置SSL证书.

Then setup your SSL certificate with LetsEncrypt in your deploy script.

这篇关于使用AWS Elastic beantalk将非www重定向到www的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 02:47