Nginx代理IISExpress获取用户IP(原创)
需要给IIS添加一个Filter,介绍地址如下:
https://devcentral.f5.com/blogs/us/x-forwarded-for-log-filter-for-windows-servers
1、配置nginx
worker_processes 1;
error_log logs/error.log;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http{
upstream myproject {
server 127.0.0.1:8888;
}
server {
listen 123.123.123.123:80;
location / {
proxy_pass http://myproject;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
}
2、配置IISExpress
在applicationhost.config的410行附近isapiFilters内添加
<filter name="F5XForwardedFor" path="%windir%\Microsoft.NET\Framework\v4.0.30319\F5XForwardedFor.dll" />
3、获取代码
context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]
原创于:http://www.cnblogs.com/errorx/
转载请注明