Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nginx preserve upstream header values, fix ip #2847

Merged
merged 1 commit into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions docker-unified/nginx/proxy.conf
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
proxy_redirect off;
proxy_set_header Host $host;

map $http_host $upstream_host {
default "$host";
~. "$http_host";
}
proxy_set_header Host $upstream_host;

proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Url-Scheme $scheme;
proxy_set_header X-Forwarded-Proto $scheme;

map $http_x_forwarded_proto $upstream_scheme {
default "$scheme";
~. "$http_x_forwarded_proto";
}
proxy_set_header X-Url-Scheme $upstream_scheme;
proxy_set_header X-Forwarded-Proto $upstream_scheme;

client_max_body_size 505m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
Expand Down
5 changes: 0 additions & 5 deletions src/Core/Utilities/CoreHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public static class CoreHelpers
private static readonly DateTime _max = new DateTime(9999, 1, 1, 0, 0, 0, DateTimeKind.Utc);
private static readonly Random _random = new Random();
private static readonly string CloudFlareConnectingIp = "CF-Connecting-IP";
private static readonly string RealIp = "X-Real-IP";

/// <summary>
/// Generate sequential Guid for Sql Server.
Expand Down Expand Up @@ -560,10 +559,6 @@ public static string GetIpAddress(this Microsoft.AspNetCore.Http.HttpContext htt
{
return httpContext.Request.Headers[CloudFlareConnectingIp].ToString();
}
if (globalSettings.SelfHosted && httpContext.Request.Headers.ContainsKey(RealIp))
{
return httpContext.Request.Headers[RealIp].ToString();
}

return httpContext.Connection?.RemoteIpAddress?.ToString();
}
Expand Down
18 changes: 15 additions & 3 deletions util/Nginx/proxy.conf
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
proxy_redirect off;
proxy_set_header Host $host;

map $http_host $upstream_host {
default "$host";
~. "$http_host";
}
proxy_set_header Host $upstream_host;

proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Url-Scheme $scheme;
proxy_set_header X-Forwarded-Proto $scheme;

map $http_x_forwarded_proto $upstream_scheme {
default "$scheme";
~. "$http_x_forwarded_proto";
}
proxy_set_header X-Url-Scheme $upstream_scheme;
proxy_set_header X-Forwarded-Proto $upstream_scheme;

client_max_body_size 505m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
Expand Down