V
V
VS2016-06-29 22:11:12
Nginx
VS, 2016-06-29 22:11:12

Why is Nginx not caching?

I started caching because of the long ttfb of my site (more than 2 seconds) in the hope that it would help
to bundle nginx + apache
site_enable.conf

proxy_cache_path /var/nginx/cache levels=1:2 keys_zone=cache:10m inactive=60m;

server {
    listen 80;
    server_name <hide>;

    log_format cache_status '[$time_local] "$request"  $upstream_cache_status';
    access_log /var/log/cache.log cache_status;

    access_log /var/log/nginx-access.log;
    error_log /var/log/nginx-error.log;

    root /var/www/html/;
    index index.php index.html index.htm;

    tcp_nodelay on;
    tcp_nopush on;

    error_page 412 = @fallback;

    proxy_cache_key "$host$request_uri";
    proxy_cache_valid 404 5m;
    proxy_cache_valid 500 501 502 503 504 1m;
    proxy_cache_valid any 10m;
    proxy_cache_use_stale http_502 http_503 http_504;
    proxy_cache_bypass $cookie_logined;
    proxy_no_cache $cookie_logined;




location / {
 if ($cookie_logined) { return 412; }
        proxy_cache cache;

        proxy_pass http://127.0.0.1:8080/;
        proxy_redirect http://127.0.0.1:8080/ /;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;

}

#location ~* ^.+\.(html|xhtml|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|tar|wav|bmp|rtf|js|wmv|avi|cur|swf|mp3|wma|htc|cur|7z)$
#{
#root /var/www/html;
#        expires 3d;
#    add_header Cache-Control "public";
#    }

open_file_cache max=10000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;



# Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
       location ~ /\. {
                deny all;
                access_log off;
                log_not_found off;
       }

#    location ~ \.(jpg|jpeg|gif|png|ico|css|bmp|swf|js|mov|avi|mp4|mpeg4) {
#    root /var/www/html;
#    }

    location ~ /.ht {
    deny all;
    }
    }

nginx.conf
user www-data;
worker_processes  auto;
timer_resolution 100ms;
worker_priority -5;

error_log  /var/log/nginx/error.log;
#error_log off;

pid        /var/run/nginx.pid;

events {
        # accept_mutex on;
        # accept_mutex_delay 500ms;
        # worker_aio_requests 32
        use epoll;
        worker_connections  2048;
        multi_accept on;
}

http {
        # Подключение mimetypes
        include /etc/nginx/mime.types;

        # Подключение прокси
        include /etc/nginx/proxy_params;

        # Не показывать информацию о сервере
        server_tokens off;

        # Логи доступа
        access_log      /var/log/nginx/access.log;
        #access_log off;

        # Протокол отдачи статики
        sendfile        on;

        tcp_nodelay on;
        tcp_nopush on;

        # Подключение других настроек
        include /etc/nginx/conf.d/*.conf;

        # Подключение виртуальных хостов
        include /etc/nginx/sites-enabled/hidden.ru;
}

core.cfg
chunked_transfer_encoding on;
client_body_buffer_size 32k;            # стандартный буфер для обычных POST
client_max_body_size 64m;               # максимальный буфер для больших файлов не больше чем у PHP
client_body_in_file_only off;
#client_body_in_single_buffer off;
client_header_buffer_size 1k;          # Маленький входной буфер
large_client_header_buffers 4 8k;       # Максимальный буфер равен входному буферу apache и PHP
#client_header_timeout 60s;
client_body_timeout 10;
client_header_timeout 10;

default_type application/octet-stream;

#directio off;
#disable_symlinks off;
#if_modified_since exact;
ignore_invalid_headers on;
underscores_in_headers on;

keepalive_disable msie6;
keepalive_requests 100;
keepalive_timeout 30;

# таймаут при передаче клиентам
send_timeout 2;
reset_timedout_connection on;

# Ограничение скорости!!!
#limit_rate 0;
#limit_rate_after 0;

# Интересное кеширование информации о мелких файлах
open_file_cache          max=4096 inactive=20s;
open_file_cache_valid    40s;
open_file_cache_min_uses 2;
open_file_cache_errors   on;

gzip.cfg
gzip on;
gzip_buffers 32 8k;
gzip_comp_level 1;
gzip_disable msie6;
gzip_min_length 20;
gzip_http_version 1.1;
gzip_proxied off;
gzip_types text/plain application/xml application/x-javascript application/javascript text/javascript text/xml ext/javascript text/css text/json application/vnd.ms-excel application/vnd.ms-powerpoint application/msword;
#gzip_types text/html application/x-javascript text/css application/javascript text/javascript text/plain text/xml application/json application/vnd.ms-fontobject application/x-font-opentype application/x-font-truetype application/x-font-ttf application/xml font/eot font/opentype font/otf image/svg+xml image/vnd.microsoft.icon;
gzip_vary off;

cache files are created. and some of the data is even cached, but not all.
Here are the logs

[29/Jun/2016:19:06:21 +0000] "GET /tehnika-dlja-kuhni/mikrovolnovye-pechi/proizvoditel:lg-2/kombinirovannye-rezhimy:mikrovolny-gril/vysota:25-2-sm/ HTTP/1.1" MISS
[29/Jun/2016:19:06:26 +0000] "GET / HTTP/1.1" MISS
[29/Jun/2016:19:06:32 +0000] "GET /tehnika-dlja-kuhni/mikrovolnovye-pechi/proizvoditel:lg-2/vnutrennij-obem:25-l/avtomaticheskaja- razmorozka:est/ HTTP/1.1" MISS
[29/Jun/2016:19:06:38 +0000] "GET /vstraivaemaja-bytovaja-tehnika/varochnye-paneli/keramicheskih-konforok:2/ HTTP/1.1" MISS
[29 /Jun/2016:18:52:57 +0000] "GET /catalog/view/javascript/jquery/ui/external/jquery.cookie.js HTTP/1.1" HIT
[29/Jun/2016:18:52:57 +0000] "GET /catalog/view/theme/lexus_happycook/stylesheet/stylesheet.css HTTP/1.1" HIT
[29/Jun/2016:18:52:57 +0000 ] "GET /catalog/view/javascript/jquery/tabs.js HTTP/1.1" HIT
/image/cache/data/mx/zadacha/p36243_2669118_vityazhka_elikor_forest_90p_650_p3g_bezheviydub_ne-250x250.jpg HTTP/1.1" -
[29/Jun/2016:09: 21:24 +0000] "GET /image/cache/data/mx/zadacha/p32124_2352796_vityazhka_krona_mini_slider_600_white-250x250.jpg HTTP/1.1" -
[29/Jun/2016:09:21:24 +0000] "GET /image/cache the HTTP /data/mx/zadacha/p269_108086_varochnaya_poverhnost_beko_hdce_32200_x_big-250x250.jpg / 1.1 "-
[29 / Jun / 2016: 09: 21: 25 +0000]" GET /image/cache/data/mx/zadacha/p24563_586245_stiralno_sushilnaya_mashina_siemens_wk14d540-250x250.jpg HTTP/1.one" -
[29/Jun/2016:09:21:25 +0000] "GET /image/cache/data/mx/zadacha/p17476_586387_ctiralnaya_mashina_hotpoint_ariston_cawd_1297-250x250.jpg HTTP/1.1" -
[29/Jun/2016:09:21:25 +0000] "GET /image/cache/data/mx/zadacha/p35263_2570560_stiralnaya_mashina_korting_kwd_1480_w-250x250.jpg HTTP/1.1" -
[29/Jun/2016:09:21:25 +0000] "GET /image/cache/data/ mx/zadacha/p19339_501991_stiralnaya_mashina_electrolux_ewx_147410w-250x250.jpg HTTP/1.1" -

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Burov, 2016-06-30
@BuriK666

Your backend gives:

Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Expires:Thu, 19 Nov 1981 08:52:00 GMT
Pragma:no-cache

Those. explicitly disables caching responses.

V
VS, 2016-06-30
@tirael777

one

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question