我在asp.net核心应用程序面前使用Nginx作为代理服务器。在我的应用程序中,我想读取客户端请求标头,特别是IP和User-Agent,但我得到的是Nginx信息。我正在使用此配置:
server {
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
listen 80;
location / {
proxy_pass http://172.18.2.3:5000;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header User-Agent $http_user_agent;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
应用程序使用以下行获取IP地址:
var remoteIpAddress = context.Connection.RemoteIpAddress;
知道可能是什么问题吗? 在此先感谢。