如何在nginx

时间:2015-08-31 12:59:13

标签: cookies nginx proxy proxypass httpcookie

我是UI编程和nginx的新手。对不起,如果问题是愚蠢的。此外,我尝试了类似于此的stackoverflow问题中出现的几乎所有答案,但没有任何帮助我解决此问题

我需要做什么:

检查是否存在名为“AUTH_COOKIE”的cookie。如果它当前的proxy_pass到site1。否则proxy_pass site2。为此,我需要阅读cookie。

我尝试了什么:

我尝试将cookie读作$ cookie_AUTH_COOKIE,但它没有提供任何结果。我尝试使用$ http_cookie阅读。也没用[/ p>

我尝试按照https://gist.github.com/rnorth/2031652https://gist.github.com/NickSto/6920790上的要点进行操作。但没用。

所以现在我只是尝试读取cookie值并使用echo返回它。响应不包含我的cookie值。

这是我使用echo

做的nginx配置
server {
    listen       3001;
    server_name  <my_host>;

    # Load configuration files for the default server block.
    # include /etc/nginx/default.d/*.conf;

    # set $auth_cookie "check";
    if ($http_cookie ~* "AUTH_COOKIE=([a-z0-9]+)(?:;|$)") {
        set $auth_cookie $1;
    }
    location / {
        resolver 8.8.8.8;
        echo "This is a test from $host with $auth_cookie. Cookie $cookie_AUTH_COOKIE. Referer $http_referer";
    }
}

当我通过advanced rest client调用此内容时,我得到了响应

This is a test from localhost with . Cookie . Referer

您可以看到$ auth_cookie,$ cookie_AUTH_COOKIE和$ http_referer都没有返回。

这是我的休息客户端的屏幕截图 Request Respnse

我在这里缺少什么。我是否需要导入任何模块来读取cookie?

1 个答案:

答案 0 :(得分:1)

屏幕截图中的请求标头中没有Cookie。

可能您无法使用此工具设置任意标头。尝试使用控制台工具,例如GETcurl -v -H 'Cookie: AUTH_COOKIE=test' http://myhost:3001。检查此命令OleDbDataReader xlsReader = new OleDbCommand("Select * from [" +spreadSheetName + "]", xlsFileConnection). ExecuteReader();