访问nginx x-accel请求标头

时间:2012-11-23 17:21:42

标签: nginx

我正在尝试使用X-Accel将有关请求的信息传递给内部重定向的uri。

  location / {
      root /web/external;
      include fastcgi.conf;
      fastcgi_param SCRIPT_FILENAME $document_root/check.php;
      fastcgi_pass unix:/services/.sock/fastcgi.sock;
   }       
   location /internal/ {
      internal;
      alias /web/internal;
      include fastcgi.conf;
      fastcgi_param SCRIPT_FILENAME $document_root/app.php;
      fastcgi_pass unix:/services/.sock/fastcgi.sock;
   }

check.php将X-Accel-Redirect标头返回到/ internal / $ uri,并且还发送我想要传递给内部请求的其他标头值。我试图使用$ sent_header_ *访问标题但它似乎不起作用。

1 个答案:

答案 0 :(得分:1)

我发现第三方模块似乎更贴合我的用例。虽然我希望这是我能找到“内置”的东西

ngx_http_auth_request_module

http://mdounin.ru/hg/ngx_http_auth_request_module/file/tip/README http://mdounin.ru/hg/ngx_http_auth_request_module/file/tip/t/auth-request-set.t

配置将更改为:

location / {
    auth_request /check;
    auth_request_set $value $upstream_http_x_value;
    add_header X-Set-Value $value;
    root /web/internal;
    include fastcgi.conf;
    fastcgi_param SCRIPT_FILENAME $document_root/app.php;
    fastcgi_pass unix:/services/.sock/fastcgi.sock;
 }       
 location /check {
    internal;
    include fastcgi.conf;
    fastcgi_param SCRIPT_FILENAME $document_root/check.php;
    fastcgi_pass unix:/services/.sock/fastcgi.sock;
 }