我在Ubuntu 16.04的Nginx后面托管了一个asp.net网络核心2.0应用程序.
我的设置如下所示:
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
ssl on;
...
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-Proto-Version $http2;
client_max_body_size 32m;
keepalive_timeout 200;
send_timeout 20;
client_body_timeout 50;
}
}
而且我在Startup.cs中也有这些设置
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor |
ForwardedHeaders.XForwardedProto
});
但是仍然每次当我尝试获取HttpContext.Connection.RemoteIpAddress时,它都会返回127.0.0.1
我应该怎么做才能解决此问题并获得真实的IP地址?
最佳答案