大网数据广告活动
服务器运维问答

Redirecting Error with google load balancer

· 52CE 我爱测

I'm trying to setup Google Load Balancer and couldn't get it work. It produces either 502 or 302 error. Wanting to direct www to non-www, http to https. This is my rewrite rule SetEnvIf X-Forwarded-Proto https HTTPS=on <VirtualHo…

问题原文

原帖链接 · FlyingPenguin · CC BY-SA 4.0

I'm trying to setup Google Load Balancer and couldn't get it work. It produces either 502 or 302 error.

Wanting to direct www to non-www, http to https.

This is my rewrite rule

    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 Load Balancer has only 1 backend service. Backend is configured for HTTP and frontend is HTTPS with 60s timeout.

  • The instance is accessible via both instance's IP and load balancer's IP
  • www to non-www is not working.
  • Http gives a 404 error.
  • https gives a 502 / 302 error.

Are the rewrite rules all wrong?

已采纳解答

原帖链接 · arcabah · CC BY-SA 4.0

As per my understanding you are trying to configure http to https in a external HTTP(S) Load Balancer, it seems that you set up a URL Rewrite rules in apache instead redirects in GCP, based on the traffic management for HTTP(S) Load Balancers, redirects includes the capability to redirect all HTTP requests to HTTPS requests, here’s an example to set up http-https redirect

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2021-07-09)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。