大网数据广告活动
服务器运维问答

What is the difference between http_cookie and cookie_name in Nginx?

· 52CE 我爱测

I want to add remote ip as a Cookie in Nginx, so that it can be passed on to AWS Load Balancer for Load balancer stickiness. location / { proxy_set_header Cookie "$http_cookie; ip=$remote_addr"; proxy_pass http://app_upstream; } …

问题原文

原帖链接 · Ashok Kumar Sahoo · CC BY-SA 3.0

I want to add remote ip as a Cookie in Nginx, so that it can be passed on to AWS Load Balancer for Load balancer stickiness.

location / {
     proxy_set_header Cookie "$http_cookie; ip=$remote_addr";
     proxy_pass http://app_upstream;
}

I am using these to set the cookie, but AWS ELB is not accepting this as stickiness. Since this server is used as an iframe, I can't use ELB generated cookie for load balancing in case of Safari/iOs which block 3rd party cookies by default.

I am open to ditching nginx and writing a custom reverse proxy as well.

已采纳解答

原帖链接 · Grumpy · CC BY-SA 3.0

The variable $http_ is about the http header. So if you have $http_host, it's grabbing the host from the header. If you say $http_cookie, you're getting the entire cookie.

The variable $cookie_ is about a specific cookie. So if you have $cookie_foo, then you get the value of the cookie named foo, which may be bar.

Cookies are passed automatically, you don't need to do anything about it unless it has a different domain or path. If you're trying to add a specific cookie, it would be:

add_header Set-Cookie foo=bar;

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-09-06)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。