Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix(docker/nginx): preserve original Host header for upstream requests (#35275)

Minamiyamad8441a8229d6
diff --git a/docker/nginx/nginx.conf.template b/docker/nginx/nginx.conf.template
index 20446fae2e0..5e26eccfe77 100644
--- a/docker/nginx/nginx.conf.template
+++ b/docker/nginx/nginx.conf.template
@@ -16,6 +16,18 @@ http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
+ # Keep Host and X-Forwarded-Port consistent so ProxyFix preserves the external port.
+ map $http_host $dify_request_host {
+ default $http_host;
+ "" $host;
+ }
+
+ map $http_host $dify_request_port {
+ default "";
+ "" $server_port;
+ ~^(?:\[[^]]+\]|[^:]+):(?<dify_host_port>[0-9]+)$ $dify_host_port;
+ }
+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
diff --git a/docker/nginx/proxy.conf.template b/docker/nginx/proxy.conf.template
index e30c8ece8a9..e489dcbc3ef 100644
--- a/docker/nginx/proxy.conf.template
+++ b/docker/nginx/proxy.conf.template
@@ -1,10 +1,10 @@
# Please do not directly edit this file. Instead, modify the .env variables related to NGINX configuration.
-proxy_set_header Host $host;
+proxy_set_header Host $dify_request_host;
# real_ip configuration must validate upstream proxies before replacing $remote_addr.
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
-proxy_set_header X-Forwarded-Port $server_port;
+proxy_set_header X-Forwarded-Port $dify_request_port;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_buffering off;