【问题标题】:Redirect Http to Https in Elastic BeansTalk, Tomcat, Nginx将 Http 重定向到 Elastic BeansTalk、Tomcat、Nginx 中的 Https
【发布时间】:2018-01-07 16:05:49
【问题描述】:

我有一个 Spring Boot 应用程序 (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 而不会陷入重定向循环。但不起作用。

【问题讨论】:

  • 如何将.ebextensions 放入 WAR 文件中进行部署,负载均衡器将如何从 WAR 中读取该文件?
  • 文件路径必须是/.ebextensions/nginx/conf.d/elasticbeanstalk/。见serverfault.com/a/822596/123651

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


【解决方案1】:

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

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

this answer on Server Fault

【讨论】:

  • 在我的负载均衡器中,端口 80 指向实例端口 5000,今天我检查了日志,并且 5000 请求从未通过 nginx。所以我再次将实例端口更改为 80 并开始工作。如果它不起作用,请确保端口 80 仅指向实例端口 80。
猜你喜欢
  • 2017-02-27
  • 2019-01-24
  • 2017-02-04
  • 2016-06-19
  • 2018-09-30
  • 2021-02-23
  • 2015-07-09
  • 2023-03-10
  • 2018-01-01
相关资源
最近更新 更多