在Elastic BeansTalk,Tomcat,Nginx中将Http重定向到Https

时间:2017-07-31 23:36:29

标签: amazon-web-services tomcat nginx spring-boot elastic-beanstalk

我有一个Spring引导应用程序(1.5.3),它运行在Tomcat容器上,Nginx作为负载均衡器。 我创建了以下文件:

.ebextentions/nginx/conf.d/myapp.conf

我根据此article添加了以下内容:

server {
  if ($http_x_forwarded_proto != 'https') {
    rewrite ^(.*) https://$host$1 redirect;
  }
}

我已在证书管理器中安装了SSL证书,并在我的环境中进行了设置。现在,该应用程序同时提供HTTP和https请求。我想将所有HTTP请求重定向到https而不会陷入重定向循环。但是没有用。

1 个答案:

答案 0 :(得分:3)

我认为你不应该将server部分添加到.conf文件中。整个.conf文件应该是这样的:

if ($http_x_forwarded_proto = 'http') {
    return 301 https://www.example.com$request_uri;
}

请参阅this answer on Server Fault