nginx继续将相同的http_cookie传递给uwsgi

时间:2012-06-18 23:22:21

标签: nginx uwsgi

我有一个小的python应用程序通过uwsgi运行,由nginx提供请求。

我正在打印环境变量......看起来在几次ok请求之后,nginx正在为不相关的请求发送相同的HTTP_COOKIE参数:

例如:

  

{'UWSGI_CHDIR':'/ ebs / py','HTTP_COOKIE':   'ge_t_c = 4fcee8450c3bee709800920c','UWSGI_SCRIPT':'服务器',   'uwsgi.version':'1.1.2','REQUEST_METHOD':'GET','PATH_INFO':   '/ redirect / ebebaf3b-475a-4010-9a72-96eeff797f1e','SERVER_PROTOCOL':   'HTTP / 1.1','QUERY_STRING':'','x-wsgiorg.fdevent.readable':   ,'CONTENT_LENGTH':'',   'uwsgi.ready_fd':无,'HTTP_USER_AGENT':'Mozilla / 5.0(兼容;   MSIE 9.0; Windows NT 6.1; WOW64; Trident / 5.0)','HTTP_CONNECTION':   'close','HTTP_REFERER':'http://www.facebook.com/','SERVER_NAME':   'pixel.domain.com','REMOTE_ADDR':'10 .load.bal.ip',   'wsgi.url_scheme':'http','SERVER_PORT':'80','wsgi.multiprocess':   是的,'uwsgi.node':'py.domain.com','DOCUMENT_ROOT':   '/ etc / nginx / html','UWSGI_PYHOME':'/ ebs / py','uwsgi.core':127,   'HTTP_X_FORWARDED_PROTO':'http','x-wsgiorg.fdevent.writable':   ,'wsgi.input':   ,   'HTTP_HOST':'track.domain.com','wsgi.multithread':错误,   'REQUEST_URI':'/ redirect / ebebaf3b-475a-4010-9a72-96eeff797f1e',   'HTTP_ACCEPT':'text / html,application / xhtml + xml, / ',   'wsgi.version':( 1,0),'x-wsgiorg.fdevent.timeout':无,   'HTTP_X_FORWARDED_FOR':'10 .load.bal.ip','wsgi.errors':,'REMOTE_PORT':'36462',   'HTTP_ACCEPT_LANGUAGE':'en-US','wsgi.run_once':错误,   'HTTP_X_FORWARDED_PORT':'80','CONTENT_TYPE':'',   'wsgi.file_wrapper':,   'HTTP_ACCEPT_ENCODING':'gzip,deflate'}

  

{'UWSGI_CHDIR':'/ ebs / py','HTTP_COOKIE':   'ge_t_c = 4fcee8450c3bee709800920c','UWSGI_SCRIPT':'服务器',   'uwsgi.version':'1.1.2','REQUEST_METHOD':'GET','PATH_INFO':   '/ redirect / 2391e658-95ef-4300-80f5-83dbb1a0e526','SERVER_PROTOCOL':   'HTTP / 1.1','QUERY_STRING':'','x-wsgiorg.fdevent.readable':   ,'CONTENT_LENGTH':'',   'uwsgi.ready_fd':无,'HTTP_USER_AGENT':'Mozilla / 5.0(iPad; CPU OS)   5_1_1与Mac OS X一样)AppleWebKit / 534.46(KHTML,与Gecko一样)   版本/ 5.1 Mobile / 9B206 Safari / 7534.48.3','HTTP_CONNECTION':   'close','HTTP_REFERER':'http://www.facebook.com/','SERVER_NAME':   'pixel.domain.com','REMOTE_ADDR':'10 .load.balancer.ip',   'wsgi.url_scheme':'http','SERVER_PORT':'80','wsgi.multiprocess':   是的,'uwsgi.node':'py.domain.com','DOCUMENT_ROOT':   '/ etc / nginx / html','UWSGI_PYHOME':'/ ebs / py','uwsgi.core':127,   'HTTP_X_FORWARDED_PROTO':'http','x-wsgiorg.fdevent.writable':   ,'wsgi.input':   ,   'HTTP_HOST':'fire.domain.com','wsgi.multithread':错误,   'REQUEST_URI':'/ redirect / 2391e658-95ef-4300-80f5-83dbb1a0e526',   'HTTP_ACCEPT':   文本/ html,应用/ XHTML + xml的,应用/ XML; Q = 0.9, / 的; Q = 0.8',   'wsgi.version':( 1,0),'x-wsgiorg.fdevent.timeout':无,   'HTTP_X_FORWARDED_FOR':'10 .load.bal.ip','wsgi.errors':,'REMOTE_PORT':'39498',   'HTTP_ACCEPT_LANGUAGE':'en-us','wsgi.run_once':错误,   'HTTP_X_FORWARDED_PORT':'80','CONTENT_TYPE':'',   'wsgi.file_wrapper':,   'HTTP_ACCEPT_ENCODING':'gzip,deflate'}

这是两个不同的客户。我打开了一个隐身会话,确认标题中没有发送cookie,并且uwsgi日志显示它收到了相同的HTTP_COOKIE。

如何确保nginx仅传递当前请求的正确信息,而不考虑其他请求?

1 个答案:

答案 0 :(得分:1)

想出来......

我必须在/ etc / nginx /

中将此行添加到uwsgi_params

uwsgi_param HTTP_COOKIE $ http_cookie;

没有它,在uwsgi / python应用程序中无法信任HTTP_COOKIE变量。