Кеширование и SSI

Igor Sysoev is at rambler-co.ru
Fri Aug 28 17:20:28 MSD 2009


On Fri, Aug 28, 2009 at 04:09:12PM +0300, Roman wrote:

> Hello Igor,
> 
> Friday, August 28, 2009, 3:31:24 PM, you wrote:
> 
> IS> On Fri, Aug 28, 2009 at 03:24:30PM +0300, Roman wrote:
> 
> >> Hello Igor,
> >> 
> >> Thursday, August 27, 2009, 3:11:15 PM, you wrote:
> >> 
> >> IS> On Thu, Aug 27, 2009 at 02:51:32PM +0300, Roman wrote:
> >> 
> >> >> Добрый день,
> >> >> имеется nginx version: nginx/0.8.10.
> >> >> 
> >> >> Собственно что пытаюсь сделать,
> >> >> страницы генерятся и кешируются правильно,
> >> >> 
> >> >> proxy_cache_key "$uri$is_args$args$cookie_auth" выглядит вот так,
> >> >> 
> >> >> кука 'auth' для каждого пользователя уникальна, получается что пользы
> >> >> от кеширования для большого кол-ва пользователей не очень много, т.к.
> >> >> все равно постоянно приходится дергать бакенд, базу и т.д.
> >> >> 
> >> >> Подумал сделать так: из ключа выкинуть $cookie_auth
> >> >> proxy_cache_key "$uri$is_args$args";
> >> >> 
> >> >> ну а идентификатор ползователей выдергивать с помощью SSI
> >> >> <!--# include virtual="/get_mem_id.php?auth=cookie_auth" set="member_id" -->
> >> >> или же получить имя
> >> >> <!--# echo var="cookie_username" default="" -->
> >> >> ну и так далее...
> >> >> 
> >> >> но что-то у меня не рабоатет, либо криво настроено, либо так нельзя
> >> >> сделать.
> >> >> 
> >> >> Подскажите, пожалуйста, как работает кеширование, а именно,
> >> >> кешируется ответ с уже обработанными SSI инструкциями или же нет?
> >> 
> >> IS> location / {
> >> IS>     ssi    on;
> >> IS>     proxy_pass ...
> >> IS>     proxy_cache_key  $request_uri;
> >> IS> }
> >> 
> >> IS> location = /get_mem_id.php {
> >> IS>     proxy_pass  ...
> >> IS>     proxy_cache_key  $cookie_auth;
> >> IS> }
> >> 
> >> Проведя эксперементы, выяснил что в такой конструкции
> >> <!--# include virtual="/get_mem_id.php?auth=cookie_auth" set="member_id" -->
> >> подзапрос "/get_mem_id.php?auth=cookie_auth"
> >> обрабатывается в том же локейшене что и основной запрос.
> 
> IS> Не должен. Нужен отладлочный лог.
> 
> 2009/08/28 14:52:32 [notice] 41368#0: *6044 "^/testredir/(.*)$" matches "/testredir/admin/gen/", client: 88.85.86.36, server: test.com, request: "GET /main.html HTTP/1.1", upstream: "http://127.0.0.2:80/index.php?query=/main.html", host: "test.com", referrer: "http://test.com/main.html"
> 2009/08/28 14:52:32 [notice] 41368#0: *6044 rewritten data: "/admin/gen/", args: "todo=index&member_id=870", client: 88.85.86.36, server: test.com, request: "GET /main.html HTTP/1.1", upstream: "http://127.0.0.2:80/index.php?query=/main.html", host: "test.com", referrer: "http://test.com/main.html"
> 2009/08/28 14:52:32 [notice] 41368#0: *6044 "^/cronjob(.*)" does not match "/get_mem_id.php", client: 88.85.86.36, server: test.com, request: "GET /main.html HTTP/1.1", subrequest: "/get_mem_id.php", host: "test.com", referrer: "http://test.com/main.html"
> 2009/08/28 14:52:32 [warn] 41368#0: *6044 an upstream response is buffered to a temporary file /usr/local/nginx/proxy_temp/9/70/0000001709 while reading upstream, client: 88.85.86.36, server: test.com, request: "GET /main.html HTTP/1.1", upstream: "http://127.0.0.2:8808/admin/gen/?todo=index&member_id=870", host: "test.com", referrer: "http://test.com/main.html"

Нужно собрать с --with-debug.

> части конфига
> ....
> location = /get_mem_id.php {
>     proxy_pass   http://127.0.0.2;
>     proxy_set_header  HOST $host;
>     proxy_set_header  X-Real-IP  $remote_addr;
>     proxy_set_header  Cookie  $http_cookie;
> 
>     proxy_cache_key "$uri$cookie_auth";
>     proxy_cache cache;
>     proxy_cache_valid 5m;
>     proxy_cache_min_uses 1;
>     proxy_cache_use_stale http_502 http_504 http_404 timeout;
>     error_log /tmp/log1.log debug;
> }
> 
> ....
> 
> location /testredir {
>     internal;
>     rewrite_log  on;
>     root /home/domains/test.com;
>     rewrite ^/testredir/(.*)$ /$1 break;
>     proxy_read_timeout 180;
>     proxy_set_header  X-Real-IP  $remote_addr;
>     proxy_set_header  REMOTE_ADDR  $remote_addr;
>     proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
>     proxy_pass http://mongrel_test.com;
> 
>     proxy_cache cache;
>     proxy_cache_key "$uri$arg_what$is_member";
>     proxy_cache_valid 5m;
>     proxy_cache_min_uses 1;
>     proxy_cache_use_stale http_502 http_504 http_404 timeout;
>     error_log /tmp/log.log debug;
> }
> ....

Вместо

 location /testredir {
     rewrite ^/testredir/(.*)$ /$1 break;
     proxy_pass http://mongrel_test.com;

достаточно

 location /testredir/ {
     proxy_pass http://mongrel_test.com/;
 

-- 
Игорь Сысоев
http://sysoev.ru





More information about the nginx-ru mailing list