大网数据广告活动
服务器运维问答

AWS Beanstalk redirect entire application from http to https

· 52CE 我爱测

The aws load balancer forwards all https requests onto the ec2 instance over port 80. I need to somehow redirect all http request on to https. What I've gathered thus far is you need to somehow modify the ec2 instance with the re…

问题原文

原帖链接 · George · CC BY-SA 4.0

The aws load balancer forwards all https requests onto the ec2 instance over port 80. I need to somehow redirect all http request on to https.

What I've gathered thus far is you need to somehow modify the ec2 instance with the redirect rules and then save the instance as a new AMI and point beanstalk to the new AMI.

I found the following rewrite rule, but unfortunately I don't know what to do with it.

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !=https
RewriteRule ^/(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]

I ssh'd into my ec2 instance and went to /etc/httpd/ and that's as far as I made it. I'm completely lost with what I'm suppose to do from there.

  1. Do I modify a file or do I create a new file?
  2. If I need to modify or create a new file, where would it be or what would I call it and where would it go?
  3. Could someone provide the exact contents of the file
  4. Once I create/modify this file what do I do next? Do I just go to the ec2 page, click on the checkbox next to my instance, click actions, and finally create image?

If so, what does all this mean? I don't know what settings I'm suppose to have here.

Lastly, I'm assuming I just go to configuration in my beanstalk dashboard and just point my beanstalk env to my new AMI and restart the server. Does this sound correct?

If someone knows how to do this or a website describing the process in detail I'd appriciate it.

I'd like to point out that I'm using a java app on tomcat. I'm not sure if a custom AMI would effect scaling up of server sizes either.

已采纳解答

原帖链接 · user1819998 · CC BY-SA 3.0

so you need to do a few things

  1. in your load balancer, have both the listeners defined i.e. for port 80 and port 443
  2. in the ec2 instance, in /etc/httpd/conf.d/elasticbeanstalk.conf - add your rewrite rule to the virtual host section
  3. Once done, when this works, you may want to create an ami image so these settings persist in an ami image you can use later to create additional instances

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2014-11-11)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0 / CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。