Created
March 20, 2020 07:37
-
-
Save ties/dd97f8b8dff831fa1f348338c5756102 to your computer and use it in GitHub Desktop.
Jinja2 fragment to define a reverse proxy
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
# Use like {{ proxy_pass('/admin', 'reljudge') }} | |
{%- macro proxy_pass(location, backend_name, host='', backend_proto='http', root=None, extra_conf=None) -%} | |
location {{ location }} { | |
{% if root != None %} | |
root {{ root }}; | |
{% endif %} | |
proxy_pass {{ backend_proto }}://{{ backend_name }}{{ location }}; | |
{% if backend_proto == 'https' %} | |
proxy_ssl_session_reuse on; | |
{% endif %} | |
{% if host %} | |
proxy_set_header Host {{ host }}; | |
{% else %} | |
proxy_set_header Host $host; | |
{% endif %} | |
proxy_set_header Connection "Upgrade"; | |
proxy_http_version 1.1; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_hide_header "Via"; | |
proxy_hide_header "X-Cache"; | |
proxy_hide_header "X-Powered-By"; | |
{% if extra_conf != None %} | |
# extra configuration: | |
{{ extra_conf }} | |
{% endif %} | |
} | |
{%- endmacro -%} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment