1

我有一个通过 uwsgi 运行的小型 python 应用程序,请求由 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': None, 'HTTP_USER_AGENT': 'Mozilla/5.0 (compatible; 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': True, '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': False, 'REQUEST_URI': '/redirect/ebebaf3b-475a-4010-9a72-96eeff797f1e', 'HTTP_ACCEPT': 'text/html, application/xhtml+xml,/ebs/py','uwsgi.core':127,'HTTP_X_FORWARDED_PROTO':'http','x-wsgiorg.fdevent.writable':,'wsgi.input':,'HTTP_HOST':'track.domain.com ', 'wsgi.multithread': False, 'REQUEST_URI': '/redirect/ebebaf3b-475a-4010-9a72-96eeff797f1e', 'HTTP_ACCEPT': 'text/html, application/xhtml+xml,/ebs/py','uwsgi.core':127,'HTTP_X_FORWARDED_PROTO':'http','x-wsgiorg.fdevent.writable':,'wsgi.input':,'HTTP_HOST':'track.domain.com ', 'wsgi.multithread': False, '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,放气'}

{'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': None, 'HTTP_USER_AGENT': 'Mozilla/5.0 (iPad; CPU OS 5_1_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B206 Safari/7534.48. 3','HTTP_CONNECTION':'关闭','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。可写': , 'wsgi.input': , 'HTTP_HOST': 'fire.domain.com', 'wsgi.multithread': False, 'REQUEST_URI': '/redirect/2391e658-95ef-4300-80f5-83dbb1a0e526', 'HTTP_ACCEPT': 'text/html,application/xhtml+xml,application/xml;q=0.9,多进程':真,'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': False, 'REQUEST_URI' : '/redirect/2391e658-95ef-4300-80f5-83dbb1a0e526', 'HTTP_ACCEPT': 'text/html,application/xhtml+xml,application/xml;q=0.9,多进程':真,'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': False, 'REQUEST_URI' : '/redirect/2391e658-95ef-4300-80f5-83dbb1a0e526', 'HTTP_ACCEPT': 'text/html,application/xhtml+xml,application/xml;q=0.9,输入': , 'HTTP_HOST': 'fire.domain.com', 'wsgi.multithread': False, 'REQUEST_URI': '/redirect/2391e658-95ef-4300-80f5-83dbb1a0e526', 'HTTP_ACCEPT': 'text/ html,应用程序/xhtml+xml,应用程序/xml;q=0.9,输入': , 'HTTP_HOST': 'fire.domain.com', 'wsgi.multithread': False, 'REQUEST_URI': '/redirect/2391e658-95ef-4300-80f5-83dbb1a0e526', 'HTTP_ACCEPT': 'text/ 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': False, 'HTTP_X_FORWARDED_PORT': '80', 'CONTENT_TYPE': '', 'wsgi.file_wrapper': , 'HTTP_ACCEPT_ENCODING':'gzip,放气'}

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

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

4

1 回答 1

2

弄清楚了...

我必须将此行添加到 /etc/nginx/ 中的 uwsgi_params

uwsgi_param HTTP_COOKIE $http_cookie;

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

于 2012-06-19T15:27:30.983 回答