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

I need to configure haproxy with multiple ssl ports

· 52CE 我爱测

I have two servers which have the same URL but the port number may change. I want to redirect these two URLs HTTPS. If I enter my first URL ( http://example.com ) then I want to it will redirect to https://example.com . If I ente…

问题原文

原帖链接 · parag bharne · CC BY-SA 3.0

I have two servers which have the same URL but the port number may change.

I want to redirect these two URLs HTTPS.

If I enter my first URL (http://example.com) then I want to it will redirect to https://example.com.

If I enter second URL (http://example.com:8080) then I want to it redirect to https://example.com:8080.

See My Configurations:

frontend www-HTTP
  bind *:80
  bind *:443 ssl crt /etc/apache2/ssl/apache.pem
  reqadd X-Forwarded-Proto:\ https
  default_backend tcp-backend
  mode tcp

frontend TCP-HTTP
  bind *:8080
  bind *:8443 ssl crt /etc/apache2/ssl/paritech.pem
  reqadd X-Forwarded-Proto:\ https
  default_backend www-backend
  mode tcp

backend www-backend
  redirect scheme https if !{ ssl_fc }
  server dev.example.com 192.168.1.120:8080 check

backend TCP-backend
  redirect scheme https if !{ ssl_fc }
  server qa.example.com 192.168.1.120:80 check

How can I redirect 8080 over 8443 for HTTPS..

已采纳解答

原帖链接 · Lutz Reinhardt · CC BY-SA 3.0

The documentation of redirect scheme says

With "redirect scheme", then the "Location" header is built by concatenating with "://" then the first occurrence of the "Host" header, and then the URI path, including the query string...

There is the problem: it is using the Host Header and there is your 8080...

Here is a possible solution:

http-request replace-header Host ^(.*?)(:[0-9]+)?$ \1:8443
http-request redirect scheme https if !{ ssl_fc }

That replace the Host header with the correct port...

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

资料来源与适用范围

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

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

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