База знаний: Linux Server
Кеширование и сжатие для домена через NGINX в Plesk 17
Автор Алексей | HiTex.BY на 24 июня 2019 10:49
|
|
Ниже представлен код осуществляющий кеширование и сжатие контента WORDPRESS сроком на 60 минут через Nginx. В файл /etc/nginx/nginx.conf в секцию http { необходимо вставить fastcgi_cache_path /var/cache/nginx levels=2 keys_zone=pagecache:5m inactive=5m max_size=1024m; Далее в файл нашего домена plesk вставляем: gzip on; gzip_proxied any; gzip_static on; gzip_types text/plain text/css application/json text/xml application/xml application/xml+rss text/javascript application/x-javascript application/javascript; gzip_comp_level 5; expires 7d; if (!-e $request_filename) { set $test P; } if ($uri !~ ^/(plesk-stat|webstat|webstat-ssl|ftpstat|anon_ftpstat|awstats-icon|internal-nginx-static-location)) { set $test "${test}C"; } if ($test = PC) { rewrite ^/(.*)$ /index.php?$1; } fastcgi_cache_key "$scheme$request_method$host$request_uri"; fastcgi_cache_use_stale error timeout invalid_header http_500; fastcgi_ignore_headers Cache-Control Expires Set-Cookie; set $skip_cache 0; # POST requests and urls with a query string should always go to PHP if ($request_method = POST) { set $skip_cache 1; } if ($query_string != "") { set $skip_cache 1; } # Don't cache uris containing the following segments if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") { set $skip_cache 1; } # Don't use the cache for logged in users or recent commenters if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") { set $skip_cache 1; } fastcgi_cache_bypass $skip_cache; fastcgi_no_cache $skip_cache; fastcgi_cache pagecache; fastcgi_cache_valid 60m; add_header X-FastCGI-Cache $upstream_cache_status; | |
|
Комментарии (0)