E
E
Evgeny Samsonov2015-08-06 00:55:33
Nginx
Evgeny Samsonov, 2015-08-06 00:55:33

What's wrong with NGINX caching?

There is a config on which caching fell off one fine day, I can’t understand why it fell off or why it worked before, since there is an error here. Own patient

server
{
    server_name site.ru www.site.ru;
 
    access_log /var/log/nginx/site.ru.access.log;
    error_log /var/log/nginx/site.ru.error.log;
    root /web/site.ru;
     
  index index.php index.html index.htm;
 
  set $skip_cache 0;
  if ($request_method = POST) 
  {
      set $skip_cache 1;
  }

  if ($query_string != "") 
  {
      set $skip_cache 1;
  }   

  if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|sitemap(_index)?.xml|/shop/|/my/|") 
  {
      set $skip_cache 1;
  }   

  if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") 
  {
      set $skip_cache 1;
  }

  if ($host ~* ^www\.(.*))
  {
    set $host_without_www $1;
    rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
  }
 
  if (!-e $request_filename)
  {
    rewrite ^(.+)$ /index.php?q=$1 last;
  }
 
  error_page 404 /index.php;
 
  location ~ .(php|html)$
  {
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param   PATH_INFO         $fastcgi_path_info;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    fastcgi_cache fcgi;
    fastcgi_cache_valid 200 15m;
    fastcgi_pass_header "X-Accel-Redirect";
    fastcgi_pass_header "X-Accel-Expires";
    fastcgi_cache_bypass $skip_cache;
    fastcgi_no_cache $skip_cache;
  }
 
  location ~ /\.ht
  {
    deny all;
  }
  
  location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf|css|js)$ 
  {
    expires 30d;
  }
}

user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
  worker_connections 768;
  multi_accept on;
}

http {
  charset utf-8;
  sendfile on;
  tcp_nopush on;
  tcp_nodelay on;
  keepalive_timeout 65;
  reset_timedout_connection on;
  server_tokens off;
  limit_req_status 403;
  limit_req_zone $binary_remote_addr zone=one:10m rate=500r/m;
  
  fastcgi_cache_path /tmp/nginx inactive=1d max_size=300m levels=1:2 keys_zone=fcgi:250m;
    fastcgi_cache_key "$scheme$request_method$host$request_uri";
    fastcgi_cache_lock on;
    fastcgi_cache_use_stale error timeout invalid_header updating http_500;
    fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
    
  types_hash_max_size 2048;
  client_max_body_size 2000m;

  include /etc/nginx/mime.types;
  default_type application/octet-stream;

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

  gzip on;
  gzip_disable "msie6";
  gzip_proxied any;
  gzip_comp_level 6;
  gzip_buffers 16 8k;
  gzip_http_version 1.1;
  gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

  include /etc/nginx/conf.d/*.conf;
  include /etc/nginx/sites-available/*;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Samsonov, 2015-08-06
@kentastik

Problem solved. Extra pipe at the end of folders.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question