nginx链接proxy_pass

时间:2011-07-13 02:53:06

标签: nginx

我正在尝试使用nginx构建反向代理服务,如果valdation成功,它将首先验证会话cookie并代理所请求的后端资源。

我有这个配置......

# upstream services 

upstream backend_production {
    #ip_hash;
    server cumulonimbus.foo.com:81;
}
map $mycookie $mybackend {
    _SESSION_COOKIE http://backend_production/session.php;
}

# session server
server {
    listen   *:80;
    server_name devcumulonimbus cumulonimbus.foo.com;

    error_log  /var/log/nginx/session.error.log;
    access_log  /var/log/nginx/session.access.log;
    #access_log  off; # turn access_log off for speed

    root /var/www/;

    location = /favicon.ico {
      return 204;
      access_log     off;
      log_not_found  off;
    }


    location / {
        proxy_set_header    Host        $http_host;
        proxy_set_header    X-Real-IP   $remote_addr;
        proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_redirect      off;
        proxy_cache off;

        # does cookie exist?
        if ($http_cookie ~* "_SESSION_COOKIE")
        {
            set $mycookie '_SESSION_COOKIE';
            proxy_pass $mybackend;

            error_page  400 403 404 500 = /denied;
            post_action /reader.php;
            break;
        }

        # no cookie
        rewrite ^(.*)$ http://cumulonimbus.foo.com:81/login.php;
    }
    location =/reader.php {
        internal;
        proxy_pass http://backend_production/reader.php;
    }
    location /denied/ {
        internal;
        rewrite ^(.*)$ http://cumulonimbus.foo.com:81/login.php;
    }
}

我在login.php中设置_SESSION_COOKIE,更新session.php中的cookie值并在reader.php中弹出一个页面。问题是我没有看到reader.php发出的页面,尽管syslog告诉我它已被命中(只显示了session.php页面)。 nginx是前端,apache是​​运行php服务的后端(此环境仅用于原型设计)。

==> /var/log/apache2/error.log <==
session_manager[4350]: CONNECTED TO SESSION MANAGER

==> /var/log/syslog <==
Jul 12 19:41:06 devcumulonimbus session_manager[4350]: CONNECTED TO SESSION MANAGER

==> /var/log/apache2/access.log <==
10.10.11.113 - - [12/Jul/2011:19:41:06 -0700] "GET /session.php HTTP/1.0" 200 454 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:5.0) Gecko/20100101 Firefox/5.0"

==> /var/log/apache2/error.log <==
web_reader[4352]: CONNECTED TO WEB READER

==> /var/log/syslog <==
Jul 12 19:41:06 devcumulonimbus web_reader[4352]: CONNECTED TO WEB READER

如果我先点击memcache,我就能看到该页面。

我还希望能够捕获第一个请求(第一个proxy_pass)的输出响应?我应该使用nginx lua模块。

0 个答案:

没有答案