简体   繁体   English

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

[英]Redirect Http to Https in Elastic BeansTalk, Tomcat, Nginx

I have a spring boot application (1.5.3) which is running on a Tomcat container with Nginx as the load balancer. 我有一个Spring Boot应用程序(1.5.3),该应用程序在Nginx作为负载均衡器的Tomcat容器上运行。 I have created below file: 我创建了以下文件:

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

And I added the below content based on this article : 我根据这篇文章添加了以下内容:

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

I have installed SSL certificate in certificate manager and set it in my environment. 我已经在证书管理器中安装了SSL证书,并在我的环境中进行了设置。 Now the application serves both HTTP and https request. 现在,该应用程序可同时满足HTTP和https请求。 I want to redirect all HTTP requests to https without falling into a redirect loop. 我想将所有HTTP请求重定向到https,而不会陷入重定向循环。 but doesn't work. 但不起作用。

I don't think you should add the server part to the .conf file. 我认为您不应该将server部分添加到.conf文件中。 The entire .conf file should be something like this: 整个.conf文件应如下所示:

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

See this answer on Server Fault . 请参阅有关服务器故障的此答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Elastic Beanstalk Linux Tomcat 8 上将 http 重定向到 https - Redirect http to https on Elastic Beanstalk Linux Tomcat 8 使用 nginx 将 Elastic Beanstalk HTTP 请求重定向到 HTTPS - Redirect Elastic Beanstalk HTTP requests to HTTPS with nginx Elastic Beanstalk Http 重定向到 Https - Elastic Beanstalk Http Redirect to Https 将http转发给https - Elastic Beanstalk + Nginx - Forward http to https - Elastic Beanstalk + Nginx 在Elastic beanstalk负载平衡器中将Http Url重定向到Https - Redirect Http Url to Https in Elastic beanstalk loadbalancer Elastic Beanstalk HTTP 至 HTTPS 重定向至 Terraform - Elastic Beanstalk HTTP to HTTPS Redirect In Terraform 对于 iis 站点,Elastic Beanstalk 将 http 重定向到 https - Elastic Beanstalk redirect http to https for iis site 如何让Elastic Beanstalk nginx支持的代理服务器从HTTP自动重定向到HTTPS? - How to get Elastic Beanstalk nginx-backed proxy server to auto-redirect from HTTP to HTTPS? Python3 + Nginx:在AWS Elastic Beanstalk上将HTTP流量重定向到HTTPS - Python3 + Nginx: Redirecting HTTP traffic to HTTPS on AWS Elastic Beanstalk 负载均衡器无法在 Elastic Beanstalk 中从 HTTP 重定向到 HTTPS - Load Balancer unable to redirect from HTTP to HTTPS in Elastic Beanstalk
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM