mail-in-a-box / mailinabox

Mail-in-a-Box helps individuals take back control of their email by defining a one-click, easy-to-deploy SMTP+everything else server: a mail server in a box.
https://mailinabox.email/
Creative Commons Zero v1.0 Universal
14.07k stars 1.44k forks source link

Reverse proxy bug due to configuration scope issues #1737

Open stateless opened 4 years ago

stateless commented 4 years ago

Please see pull request: #1432

Also: https://discourse.mailinabox.email/t/reverse-proxy-bug-due-to-configuration-scope-issues/3745

stateless commented 4 years ago

Ping.

Here is the patch code:

diff --git a/management/web_update.py b/management/web_update.py
index 72295c2..27e6efc 100644
--- a/management/web_update.py
+++ b/management/web_update.py
@@ -156,8 +156,12 @@ def make_domain_config(domain, templates, ssl_certificates, env):
                        # any proxy or redirect here?
                        for path, url in yaml.get("proxies", {}).items():
                                nginx_conf_extra += "\tlocation %s {" % path
-                               nginx_conf_extra += "\n\t\tproxy_pass %s;" % url
+                               nginx_conf_extra += "\n\t\tproxy_set_header Host $http_host;"
+                               nginx_conf_extra += "\n\t\tproxy_set_header X-Real-IP $remote_addr;"
                                nginx_conf_extra += "\n\t\tproxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;"
+                               nginx_conf_extra += "\n\t\tproxy_set_header X-Forwarded-Host $http_host;"
+                               nginx_conf_extra += "\n\t\tproxy_set_header X-Forwarded-Proto $scheme;"
+                               nginx_conf_extra += "\n\t\tproxy_pass %s;" % url
                                nginx_conf_extra += "\n\t}\n"
                        for path, url in yaml.get("redirects", {}).items():
                                nginx_conf_extra += "\trewrite %s %s permanent;\n" % (path, url)
stateless commented 4 years ago

@JoshData