server { listen 10001; server_name localhost; default_type text/html; location = /favicon.ico { log_not_found off; access_log off; } set $userName ""; if ($http_cookie ~* "UserName=(.+?)(?=;|$)") { set $userName $1; }
set $realIp $remote_addr; if ($http_cookie ~* "ClientRealIp") { set $realIp $cookie_ClientRealIp; } proxy_set_header X-Real-IP $realIp; }
方式1:正则表达式
set $userName ""; if ($http_cookie ~* "UserName=(.+?)(?=;|$)") { set $userName $1; }
方式2:$cookie_
set $realIp $remote_addr; if ($http_cookie ~* "ClientRealIp") { set $realIp $cookie_ClientRealIp; }
标签:userName,set,http,获取,cooike,nginx,cookie,realIp,ClientRealIp From: https://www.cnblogs.com/bobobjh/p/18185719