如何在openshift golang应用程序上将HTTP重定向到https?

问题描述:

我有一个可扩展的golang应用程序在openshift免费层上运行.它使用位于 https://github.com/zolamk/openshift-go ,我想将http重定向到https,我尝试按照

I have a scaled golang application running on the openshift free tier. It uses a custom cartidge located at https://github.com/zolamk/openshift-go and i want to redirect http to https, i tried following the guide at Technical FAQs by using .htaccess file but that didn't work, maybe because haproxy is used as a load balancer, so my question is how can i redirect HTTP traffic to HTTPS without touching my application code if possible? maybe by changing the haproxy.cfg file, here is what my `haproxy.cfg file looks like

defaults
    mode                    http
    log                     global
    option                  httplog
    option                  dontlognull
    option http-server-close
    #option forwardfor       except 127.0.0.0/8
    option                  redispatch
    retries                 3
    timeout http-request    10s
    timeout queue           1m
    timeout connect         10s
    timeout client          1m
    timeout server          1m
    timeout http-keep-alive 10s
    timeout check           10s
    maxconn                 128

listen stats 127.9.80.3:8080
    mode http
    stats enable
    stats uri /

listen express 127.9.80.2:8080
    cookie GEAR insert indirect nocache
    option httpchk GET /
    http-check expect rstatus 2..|3..|401

    balance leastconn
    server gear-586a4c732d52711f96000127-zolamk ex-std-node847.prod.rhcloud.com:65326 check fall 2 rise 3 inter 2000 cooki$
    server local-gear 127.9.80.1:8080 check fall 2 rise 3 inter 2000 cookie local-586a492489f5cfef6a00002a

谢谢.

如果要将流量强制为https,可以将以下内容添加到侦听部分:

If you want to force traffic to https you can add the following to your listen section :

redirect scheme https code 301 if !{ ssl_fc }

但是您也需要在端口443上监听

but you'd need to to be listening on port 443 aswell