本文介绍了如何在openshift golang应用程序上将HTTP重定向到https?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可扩展的golang应用程序在openshift免费层上运行.它使用位于 https://github.com/zolamk/openshift-go ,我想将http重定向到https,我尝试按照技术常见问题解答(通过使用.htaccess文件进行操作,但没有用),也许是因为 haproxy 被用作负载平衡器,所以我问题是如何在不接触我的应用程序代码的情况下如何将HTTP流量重定向到HTTPS?也许是通过更改haproxy.cfg文件,这是我的`haproxy.cfg文件的样子

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

这篇关于如何在openshift golang应用程序上将HTTP重定向到https?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 18:58