[英]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.