首页 > 解决方案 > 谷歌负载均衡器重定向错误

问题描述

我正在尝试设置 Google 负载均衡器,但无法正常工作。它会产生 502 或 302 错误。

想要将 www 指向非 www,将 http 指向 https。

这是我的重写规则

    SetEnvIf X-Forwarded-Proto https HTTPS=on
    <VirtualHost _default_:80>
      DocumentRoot "/opt/bitnami/apache/htdocs"
      Include "/opt/bitnami/apps/letsencrypt/conf/httpd-prefix.conf"
      <IfModule mod_proxy.c>
        ProxyPass /.well-known !
      </IfModule>
      RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
      RewriteCond %{HTTP_HOST} !^localhost
      RewriteCond %{HTTP_HOST} !^[0-9]+.[0-9]+.[0-9]+.[0-9]+(:[0-9]+)?$
      RewriteCond %{REQUEST_URI} !^/\.well-known
      RewriteRule ^(.*)$ http://%1$1 [R=permanent,L]
<VirtualHost _default_:443>

  RewriteEngine On
  RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
  RewriteCond %{HTTP_HOST} !^localhost
  RewriteCond %{HTTP_HOST} !^[0-9]+.[0-9]+.[0-9]+.[0-9]+(:[0-9]+)?$
  RewriteCond %{REQUEST_URI} !^/\.well-known
  RewriteRule ^(.*)$ https://%1$1 [R=permanent,L]

Google 负载均衡器只有 1 个后端服务。后端为 HTTP 配置,前端为 HTTPS。

重写规则都错了吗?

标签: sslmod-rewritegoogle-cloud-platformurl-rewritingload-balancing

解决方案


推荐阅读