简体   繁体   English

使用 Application Load Balancer 将 http 重定向到 https

[英]Redirect http to https using Application Load Balancer

I am using an application load balancer to map certain paths to one server (Apache) and other paths to another server (Tomcat).我正在使用应用程序负载平衡器来 map 某些路径到一台服务器 (Apache) 和其他路径到另一台服务器 (Tomcat)。

I made all pages on my site available via https by setting up an https listener on the load balancer.我通过在负载均衡器上设置一个https 侦听器,使我网站上的所有页面都可以通过 https 访问。

So that requests from client to load balancer are encrypted but from load balancer to servers are not.因此,从客户端到负载均衡器的请求是加密的,但从负载均衡器到服务器的请求不是。

Now, I would also like to redirect all http requests to https.现在,我还想将所有 http 请求重定向到 https。

Are there any suggestions how I can do this?有什么建议我该怎么做吗?

I can redirect each server separately (ie: redirect tomcat http requests as outlined here and redirect Apache http request with redirect rules).我可以分别重定向每个服务器(即:重定向 tomcat http 请求,如此处所述并使用重定向规则重定向 Apache http 请求)。 However, I was wondering if there is a simpler way to do it (ie: where I would only have 1 redirect rather than a separate redirect for each server).但是,我想知道是否有更简单的方法来做到这一点(即:我只有 1 个重定向而不是每个服务器的单独重定向)。

Thanks.谢谢。

I found this while I was looking for a solution for the same problem. 当我在寻找同样问题的解决方案时,我发现了这一点。 This has code sample for Apache, Nginx and IIS. 这包含Apache,Nginx和IIS的代码示例。

<VirtualHost *:80>

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule .* https://%{HTTP:Host}%{REQUEST_URI} [L,R=permanent]

</VirtualHost>

https://aws.amazon.com/premiumsupport/knowledge-center/redirect-http-https-elb/ https://aws.amazon.com/premiumsupport/knowledge-center/redirect-http-https-elb/

You have to configure the following to conf/server.xml您必须将以下内容配置为 conf/server.xml

<Connector
port="8080"
protocol="HTTP/1.1"
scheme="https"
secure="true"
connectionTimeout="20000"
URIEncoding="UTF-8"
redirectPort="8443" />

Please ensure scheme="https" is added so that no http request is being made.请确保添加了 scheme="https",以便不会发出 http 请求。

Along with above add the default HSTS filters available in the conf/web.xml as defined in the tomcat documentation.除上述内容外,还添加了 conf/web.xml 中可用的默认 HSTS 过滤器,如 tomcat 文档中所定义。

Please refer here for more info: Tomcat behind LB详情请参考这里: LB后面的Tomcat

暂无
暂无

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

相关问题 将 http 重定向到 https AWS 应用程序负载均衡器 - Redirect http to https AWS Application Load Balancer 如何使用 GCP 负载均衡器将 HTTP 重定向到 HTTPS - How to redirect HTTP to HTTPS using GCP load balancer 负载均衡器无法在 Elastic Beanstalk 中从 HTTP 重定向到 HTTPS - Load Balancer unable to redirect from HTTP to HTTPS in Elastic Beanstalk 是否有选项将 http 流量重定向到 aws.network 负载均衡器中的 https - Is there option to redirect http traffic to https in aws network load balancer Elastic Beans + Django。使用负载均衡器将 HTTP 切换为 HTTPS - Elastic Beans + Django. Switch HTTP to HTTPS using Load Balancer 如何为使用 GKE 部署的应用程序添加 HTTPS 负载均衡器 - How to add HTTPS load balancer for an application deployed using GKE Google Cloud Load Balancer 中的 HTTP 到 HTTPS 重定向不适用于多个域 - HTTP-to-HTTPS redirect in Google Cloud Load Balancer doesn't work for multiple domains 将 Elastic Beanstalk 健康检查程序的协议更改为 HTTPS 而不是普通的 HTTP(应用程序负载均衡器) - Change protocol of Elastic Beanstalk health checker to HTTPS instead of plain HTTP (Application load balancer) 为什么 AWS 的 Application Load Balancer 在使用 HTTPS 时需要自定义域? - Why does AWS's Application Load Balancer require a custom domain when using HTTPS? Google 负载均衡器(经典)- 更改前端以支持 HTTPS 重定向 - Google Load Balancer (classic) - change Frontend to support HTTPS redirect
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM