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

How can you redirect HTTP to HTTPS (GCP Load Balancing)?

· 52CE 我爱测

I'm playing with GCP Load Balancing and want to redirect HTTP to HTTPS links. But cannot figure out. My Load Balancing looks like: Load balancer name Front End: Protocols IP Certificate HTTP x.x.x.x:80 - HTTPS x.x.x.x:443 example…

问题原文

原帖链接 · Ng Nam · CC BY-SA 3.0

I'm playing with GCP Load Balancing and want to redirect HTTP to HTTPS links. But cannot figure out.

My Load Balancing looks like:

Load balancer name
Front End:
  Protocols     IP             Certificate
  HTTP          x.x.x.x:80     -
  HTTPS         x.x.x.x:443    example-com

Back End: 
  Hosts          Paths        Backend
  example.com    /*           webs-backend

My webs backend is a simple nginx web server that listens on TCP/80 port. Nginx server configs:

server {
  server_name example.com;
  root /var/www/html;

  <snip>
}

Now with this GCP Load Balancing setup, I can access both HTTP and HTTPS, tried to configure Nginx to send cleints 301 redirect to HTTPS and it won't work. Too many redirects.

Question is, how can I configure GCP Load Balancing to redirect HTTP to HTTPS properly?

社区高分解答

原帖链接 · N Singh · CC BY-SA 3.0

There is feature request submitted to Google product engineering team to support it on GCP HTTP(s) load-balancer. You can track this on Google public issue tracker.

There is a thread discussing the same and in NGINX server you can accomplish the same by adding following string into nginx configuration file like this:

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

You can check this thread as well which may help you.

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

资料来源与适用范围

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

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

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