问题
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
Thanks.
回答1:
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 }
but you'd need to to be listening on port 443 aswell
来源:https://stackoverflow.com/questions/41428408/how-to-redirect-http-to-https-on-an-openshift-golang-app