Last active
October 25, 2021 12:16
-
-
Save guilhem/52a2722eceffcd7a29b3b5687deedcd6 to your computer and use it in GitHub Desktop.
fix nginx.ingress.kubernetes.io/force-ssl-redirect="true" with cloudlare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: v1 | |
kind: ConfigMap | |
metadata: | |
name: cloudflare-forwarded-port | |
namespace: ingress-nginx | |
data: | |
main.lua: | | |
local ngx = ngx | |
local _M = {} | |
function _M.rewrite() | |
if (ngx.var.http_cf_visitor and ngx.var.http_cf_visitor:find( "https")) then | |
-- ngx.log(ngx.WARN, "testssl headers ", ngx.req.get_headers()) | |
ngx.req.set_header("X-Forwarded-Proto", "https") | |
ngx.req.set_header("X-Forwarded-Port", "443") | |
end | |
end | |
return _M |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local ngx = ngx | |
local _M = {} | |
function _M.rewrite() | |
if (ngx.var.http_cf_visitor and ngx.var.http_cf_visitor:find( "https")) then | |
-- ngx.log(ngx.WARN, "testssl headers ", ngx.req.get_headers()) | |
ngx.req.set_header("X-Forwarded-Proto", "https") | |
ngx.req.set_header("X-Forwarded-Port", "443") | |
end | |
end | |
return _M |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: v1 | |
kind: ConfigMap | |
metadata: | |
name: nginx-configuration | |
namespace: ingress-nginx | |
labels: | |
app: ingress-nginx | |
data: | |
[...] | |
plugins: "cloudflare-forwarded-port" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: apps/v1 | |
kind: DaemonSet | |
metadata: | |
name: nginx-ingress-controller | |
namespace: ingress-nginx | |
spec: | |
template: | |
spec: | |
containers: | |
- name: nginx-ingress-controller | |
volumeMounts: | |
- name: cloudflare-forwarded-port | |
mountPath: /etc/nginx/lua/plugins/cloudflare-forwarded-port | |
volumes: | |
- name: cloudflare-forwarded-port | |
configMap: | |
name: cloudflare-forwarded-port |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment