将http重定向到https google cloud负载平衡 [英] Redirect http to https google cloud load balance

查看:126
本文介绍了将http重定向到https google cloud负载平衡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了https负载平衡并添加了SSL证书.网站使用https://,但无法使用http://并收到404错误

I have created https load balance and added ssl certificate. site working with https:// but its not working http:// and getting 404 error

在负载平衡标头请求中将标头名称添加为X-Forwarded-Proto,将avlue添加为https

Added Headername as X-Forwarded-Proto and avlue as https in load balace header request

添加到.htaccess中

Added in .htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

是否有任何将http重定向到https以避免404错误的方法?

is there any to redirect http to https to avoid 404 error?

推荐答案

目前,无法直接配置GCP负载均衡器以将流量从HTTP重定向到HTTPS.但是,有一种解决方法可以做到这一点.使用Nginx,您可以在nginx配置文件中添加以下字符串:

At this time, there is no way to directly configure the GCP Load Balancer to redirect traffic from HTTP to HTTPS; however, there is a workaround to do this. Using Nginx, you can add the following string within the nginx configuration file:

if ($http_x_forwarded_proto = "http") { 
      return 301 https://$host$request_uri; 
    }

如果您使用的是Apache,那么如果要使用.htaccess文件重定向流量,则必须执行以下操作:

If you are using Apache, then you will have to do the following if you want to redirect the traffic using the .htaccess file:

  1. 根据所运行的Linux操作系统,运行"sudo a2enmod rewrite"或"LoadModule rewrite_module modules/mod_rewrite.so".这将启用
  2. 使用以下命令在域根目录中编辑或创建.htaccess文件:

  1. Run either "sudo a2enmod rewrite" or "LoadModule rewrite_module modules/mod_rewrite.so" depending on the Linux OS you are running. This will enable
  2. Edit or create the .htaccess file in the domain root directory with the following:

RewriteEngine开启RewriteCond%{HTTPS}!= onRewriteRule ^/?(.*) https://% {SERVER_NAME}/$ 1 [R,L]

RewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

您可以在以下链接上找到更多详细信息,此处.

You can find more details on the following link here.

还有一个内部请求,要求在GCP HTTP/HTTPS负载均衡器中添加此功能.我无法提供是否适用/何时适用的预计到达时间;但是,您可以按照公共问题跟踪程序(PIT)进行请求.

There is also an internal request to have this feature added within GCP HTTP/HTTPS Load Balancers. I cannot provide an ETA on if/when it will be applied; however, you can follow the Public Issue Tracker (PIT) on the progress of the request.

这篇关于将http重定向到https google cloud负载平衡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆