<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Добрый день.</div><div dir="ltr"><br></div><div dir="ltr">Что-то у меня не сходится, не понимаю:</div><div dir="ltr"><br></div><div>Запрос в <span style="font:400 13.33px/19.99px Arial,Helvetica,sans-serif;text-align:left;color:rgb(34,34,34);text-transform:none;text-indent:0px;letter-spacing:normal;text-decoration:none;word-spacing:0px;display:inline;white-space:normal;font-size-adjust:none;font-stretch:100%;float:none;background-color:transparent">22/May/2019:17:15:43</span></div><div><span style="font:400 13.33px/19.99px Arial,Helvetica,sans-serif;text-align:left;color:rgb(34,34,34);text-transform:none;text-indent:0px;letter-spacing:normal;text-decoration:none;word-spacing:0px;display:inline;white-space:normal;font-size-adjust:none;font-stretch:100%;float:none;background-color:transparent">Файл элемента кеша создан  <span style="font:400 13.33px/19.99px Arial,Helvetica,sans-serif;text-align:left;color:rgb(34,34,34);text-transform:none;text-indent:0px;letter-spacing:normal;text-decoration:none;word-spacing:0px;display:inline;white-space:normal;font-size-adjust:none;font-stretch:100%;float:none;background-color:transparent">May 18 12:46 </span></span></div><div><span style="font:400 13.33px/19.99px Arial,Helvetica,sans-serif;text-align:left;color:rgb(34,34,34);text-transform:none;text-indent:0px;letter-spacing:normal;text-decoration:none;word-spacing:0px;display:inline;white-space:normal;font-size-adjust:none;font-stretch:100%;float:none;background-color:transparent"><span style="font:400 13.33px/19.99px Arial,Helvetica,sans-serif;text-align:left;color:rgb(34,34,34);text-transform:none;text-indent:0px;letter-spacing:normal;text-decoration:none;word-spacing:0px;display:inline;white-space:normal;font-size-adjust:none;font-stretch:100%;float:none;background-color:transparent">inactive=1d</span></span></div><div><span style="font:400 13.33px/19.99px Arial,Helvetica,sans-serif;text-align:left;color:rgb(34,34,34);text-transform:none;text-indent:0px;letter-spacing:normal;text-decoration:none;word-spacing:0px;display:inline;white-space:normal;font-size-adjust:none;font-stretch:100%;float:none;background-color:transparent"><span style="font:400 13.33px/19.99px Arial,Helvetica,sans-serif;text-align:left;color:rgb(34,34,34);text-transform:none;text-indent:0px;letter-spacing:normal;text-decoration:none;word-spacing:0px;display:inline;white-space:normal;font-size-adjust:none;font-stretch:100%;float:none;background-color:transparent">ответ 302</span></span></div><div><span style="text-align:left;color:rgb(34,34,34);text-transform:none;line-height:19.99px;text-indent:0px;letter-spacing:normal;font-family:Arial,Helvetica,sans-serif;font-size:13.33px;font-variant:normal;word-spacing:0px;display:inline;white-space:normal;font-size-adjust:none;font-stretch:100%;float:none;background-color:transparent"><span style="text-align:left;color:rgb(34,34,34);text-transform:none;line-height:19.99px;text-indent:0px;letter-spacing:normal;font-family:Arial,Helvetica,sans-serif;font-size:13.33px;font-variant:normal;word-spacing:0px;display:inline;white-space:normal;font-size-adjust:none;font-stretch:100%;float:none;background-color:transparent"><span style="font:400 13.33px/19.99px courier new,monospace;text-align:left;color:rgb(34,34,34);text-transform:none;text-indent:0px;letter-spacing:normal;text-decoration:none;word-spacing:0px;display:inline;white-space:normal;font-size-adjust:none;font-stretch:100%;float:none;background-color:transparent">proxy_cache_valid         301 302 404 15s;</span></span></span></div><div><span style="text-align:left;color:rgb(34,34,34);text-transform:none;line-height:19.99px;text-indent:0px;letter-spacing:normal;font-family:Arial,Helvetica,sans-serif;font-size:13.33px;font-variant:normal;word-spacing:0px;display:inline;white-space:normal;font-size-adjust:none;font-stretch:100%;float:none;background-color:transparent"><span style="text-align:left;color:rgb(34,34,34);text-transform:none;line-height:19.99px;text-indent:0px;letter-spacing:normal;font-family:Arial,Helvetica,sans-serif;font-size:13.33px;font-variant:normal;word-spacing:0px;display:inline;white-space:normal;font-size-adjust:none;font-stretch:100%;float:none;background-color:transparent"><b></b><i></i><u></u><sub></sub><sup></sup><strike></strike><br></span></span></div><div><span style="text-align:left;color:rgb(34,34,34);text-transform:none;line-height:19.99px;text-indent:0px;letter-spacing:normal;font-family:Arial,Helvetica,sans-serif;font-size:13.33px;font-variant:normal;word-spacing:0px;display:inline;white-space:normal;font-size-adjust:none;font-stretch:100%;float:none;background-color:transparent"><span style="text-align:left;color:rgb(34,34,34);text-transform:none;line-height:19.99px;text-indent:0px;letter-spacing:normal;font-family:Arial,Helvetica,sans-serif;font-size:13.33px;font-variant:normal;word-spacing:0px;display:inline;white-space:normal;font-size-adjust:none;font-stretch:100%;float:none;background-color:transparent">Более подробно:</span></span></div><div dir="ltr"><b></b><i></i><u></u><sub></sub><sup></sup><strike></strike><b></b><i></i><u></u><sub></sub><sup></sup><strike></strike><b></b><i></i><u></u><sub></sub><sup></sup><strike></strike><br></div><div dir="ltr"><br></div><div dir="ltr">В логе запрос с попаданием в кеш</div><blockquote style="padding:0px;margin-top:0px;margin-right:0px;margin-bottom:0px" dir="ltr"><div>[22/May/2019:17:15:43 +0300] "/s13/27/public_pin_l/241/2352410650.jpg" ip=15.85.172.17 status=302 size=0 upTime=- upstream_addr=- upstream_status=- request_time=0.000 cache=HIT ref="-" http</div></blockquote><div dir="ltr">Вычисляем файл кеша:</div><blockquote style="padding:0px;margin-top:0px;margin-right:0px;margin-bottom:0px" dir="ltr"><div>echo -n /s13/27/public_pin_l/241/2352410650.jpg | md5sum<br>044e2e2e9226a8f10d25d480a49d2000</div></blockquote><div dir="ltr">Вот он </div><blockquote style="padding:0px;margin-top:0px;margin-right:0px;margin-bottom:0px" dir="ltr"><div>-rw------- 1 www-data www-data 684 May 18 12:46 044e2e2e9226a8f10d25d480a49d2000<br><br></div></blockquote><div dir="ltr">Содержит он</div><blockquote style="padding:0px;margin-top:0px;margin-right:0px;margin-bottom:0px" dir="ltr"><div><br>cat 044e2e2e9226a8f10d25d480a49d2000<br>ђa]яяяяяяяяђФЯ\ТYЁK~¬<br>KEY: /s13/27/public_pin_l/241/2352410650.jpg<br>HTTP/1.1 302 Found<br>Server: nginx/1.15.8<br>Date: Sat, 18 May 2019 09:46:56 GMT<br>Content-Length: 0<br>Connection: close<br>Cache-Control: max-age=2592000<br>Expires: Mon, 17 Jun 2019 09:46:56 GMT<br>Location: /s107/797257fdf5bc88f5/2352410650.jpg<br>Pragma: no-cache<br>X-Powered: iconv<br>Content-Type: image/jpeg<br><br></div></blockquote><div dir="ltr">Конфиг вот такой:</div><div dir="ltr"><br></div><blockquote style="padding:0px;margin-top:0px;margin-right:0px;margin-bottom:0px" dir="ltr"><div><font face="courier new,monospace">user  www-data;<br>worker_processes  auto;<br>worker_rlimit_nofile 160000;</font></div><div><font face="courier new,monospace">thread_pool pool_1 threads=128;<br>thread_pool pool_2 threads=128;</font></div><div><font face="courier new,monospace">error_log   /var/log/nginx/error.log warn;<br></font><font face="courier new,monospace">events {<br></font></div><div><font face="courier new,monospace">    worker_connections  150000;<br>    use epoll;<br>}</font></div><div><font face="courier new,monospace">http {<br>    server_tokens off;</font></div><div><font face="courier new,monospace">    include       mime.types;<br>    default_type  application/octet-stream;</font></div><div><font face="courier new,monospace">    log_format  stat        '[$time_local] "$request_uri" ip=$remote_addr status=$status size=$body_bytes_sent upTime=$upstream_response_time upstream_addr=$upstream_addr upstream_status=$upstream_status'<br></font></div><div><font face="courier new,monospace">                            ' request_time=$request_time cache=$upstream_cache_status ref="$http_referer" $scheme $http2';<br></font><font face="courier new,monospace">    log_not_found       off;</font></div><div><font face="courier new,monospace">    sendfile       on;<br>    tcp_nopush     on;</font></div><div><font face="courier new,monospace">    keepalive_timeout  300;</font></div><div><font face="courier new,monospace">    gzip  off;<br>    reset_timedout_connection on;</font></div><div><font face="courier new,monospace">    client_body_buffer_size 128k;<br>    client_max_body_size    20m;</font></div><div><font face="courier new,monospace">    open_file_cache          max=10000 inactive=5m;<br>    open_file_cache_valid    2m;<br>    open_file_cache_min_uses 1;<br>    open_file_cache_errors   on;</font></div><div><font face="courier new,monospace">    proxy_temp_path           /run/shm;<br>    proxy_cache_key           $uri$is_args$args;<br>    proxy_cache_valid         200 30d;<br><div>    proxy_cache_valid         301 302 404 15s;<br></div>    proxy_cache_lock          off;<br>    proxy_cache_use_stale     error timeout invalid_header http_500 http_502 http_503 http_504 http_404;<br>    proxy_redirect            off;<br>    recursive_error_pages     on;<br>    proxy_buffers             16 16k;<br>    proxy_buffer_size         64k;<br>    proxy_ignore_client_abort off;<br>    proxy_intercept_errors    on;<br>    proxy_next_upstream       error timeout invalid_header http_500 http_502 http_503 http_504 http_404;<br>    proxy_set_header          Host                $host;<br>    proxy_set_header          X-Real-IP           $remote_addr;<br>    proxy_set_header          X-Forwarded-For     $proxy_add_x_forwarded_for;<br>    proxy_max_temp_file_size  0;</font></div><div><font face="courier new,monospace">    include upstream/upstream_cache.conf;<br>    include upstream/upstream_storage.conf;<br>    include upstream/all_in_one_storage_upstream.conf;<br>    include nginx.ssl.conf;</font></div><div><font face="courier new,monospace">    proxy_cache_path /ssd     levels=1:2 keys_zone=ssd1:2000m max_size=175000m inactive=1d loader_files=1000 use_temp_path=off;<br>    proxy_cache_path /ssd2    levels=1:2 keys_zone=ssd2:2000m max_size=205000m inactive=1d loader_files=1000 use_temp_path=off;</font></div><div><font face="courier new,monospace">    split_clients $uri$is_args$args $disk {<br>        56.3%     2;<br>        *         1;<br>    }</font></div><div><font face="courier new,monospace"><br></font></div><div><font face="courier new,monospace">    aio threads=pool_$disk;<br>    proxy_cache ssd$disk;</font></div><div><font face="courier new,monospace">    server {<br></font></div><div><font face="courier new,monospace">        server_name             <a href="http://8.local.net">8.local.net</a>;<br>        listen                  80  backlog=102400          default;<br>        listen                  443 backlog=102400 ssl http2 default;</font></div><div><font face="courier new,monospace">        root /etc/nginx/html;<br>        access_log /var/log/nginx/access_basic.log stat;<br></font></div><div><font face="courier new,monospace">        location / {<br>            try_files $uri @to_neighbor;<br>        }</font></div><div><font face="courier new,monospace">        location = /error404.html {<br>            return 404 "No such file";<br>        }</font></div><div><font face="courier new,monospace">        location @to_neighbor {<br>            internal;</font></div><div><font face="courier new,monospace">            access_log  /var/log/nginx/access_full.log stat;<br></font><font face="courier new,monospace">            proxy_pass  <a href="http://cache_">http://cache_</a>$real_host;</font></div><div><font face="courier new,monospace">            error_page 400 /error404.html;<br></font></div><div><font face="courier new,monospace">            error_page 404 = @to_storage;<br>            error_page 502 = @to_storage;<br>            error_page 504 = @to_storage;<br>            error_page 503 = @to_storage;<br>        }<br>        location @to_storage {<br>            if ( $request_method = PURGE ) { return 200; }<br>            internal;</font></div><div><font face="courier new,monospace">            access_log  /var/log/nginx/access_full.log stat;<br>            access_log  /var/log/nginx/access_stat.log stat if=$do_log;<br>            include logs.inc;</font></div><div><font face="courier new,monospace">            proxy_pass  <a href="http://all-storages">http://all-storages</a>;</font></div><div><font face="courier new,monospace">            error_page 400 /error404.html;<br>        }</font></div><div><font face="courier new,monospace">    }</font></div><div><font face="courier new,monospace">} # end of http</font><br><br></div></blockquote><div><br></div><div dir="ltr"><br></div></div></div></div></div></div></div></div></div><br><div class="gmail_quote"><div class="gmail_attr" dir="ltr">вт, 21 мая 2019 г. в 17:22, Maxim Dounin <<a href="mailto:mdounin@mdounin.ru">mdounin@mdounin.ru</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid">Hello!<br>
<br>
On Tue, May 21, 2019 at 04:31:46PM +0300, kpoxa wrote:<br>
<br>
> Есть некоторые директивы, про которые не совсем понятно, как они работают<br>
> вместе, в частности у proxy_cache_path есть параметр inactive, который<br>
> задаёт время жизни файла в кеше, считая с последнего обращения. А еще есть<br>
> директива proxy_cache_valid, судя по описанию которой, которая тоже<br>
> отвечает за что-то подобное, обозванное временем кеширования.<br>
> <br>
> И в связи с этим у меня вопрос:<br>
> как мне настроить кеш так, чтобы 302 редиректы кешировались на 15 секунд?<br>
> При настройках inactive=7d никакие варианты прописать proxy_cache_valid 302<br>
> 15s не работают, в кеше куча вчерашних редиректов.<br>
> И второй вопрос - при каких условиях и как работает proxy_cache_valid ?<br>
> Пока что у меня не сходятся реальное поведение с документацией.<br>
<br>
Директива proxy_cache_valid - определяет, сколько времени ответ в <br>
кэше будет считаться валидным, то есть пригодным для возврата <br>
клиенту.  Используется, если клиент не вернул явного указания <br>
через Cache-Control/Expires/X-Accel-Expires (или они <br>
проигнорированы в соответствии с proxy_ignore_headers).<br>
<br>
Параметр inactive директивы proxy_cache_path - определяет, сколько <br>
времени ответ, возможно уже устаревший, будет хранится в кэше <br>
после последнего обращения.  Этот параметр - используется в первую <br>
очередь для управления размером кэша на диске.<br>
<br>
Когда inactive больше valid - в кэше будут храниться устаревшие <br>
ответы.  Такие ответы в норме не возвращаются клиентам, но могут <br>
быть использованы, скажем, в случае ошибок, с помощью директивы <br>
proxy_cache_use_stale.<br>
<br>
-- <br>
Maxim Dounin<br>
<a href="http://mdounin.ru/" target="_blank" rel="noreferrer">http://mdounin.ru/</a><br>
_______________________________________________<br>
nginx-ru mailing list<br>
<a href="mailto:nginx-ru@nginx.org" target="_blank">nginx-ru@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx-ru" target="_blank" rel="noreferrer">http://mailman.nginx.org/mailman/listinfo/nginx-ru</a></blockquote></div>