Итак, я установил плагин W3 Total Cache для управления своим кешем на моем веб-сайте. Я использую сервер NGINX. Я произвел желаемые настройки, и плагин сгенерировал файл с именем «nginx .conf» в моей папке root.
Я пытаюсь включить его в файл виртуального хоста, в серверный блок - не работает
Я создал другой файл с именем «w3-total» в «sites-available» папка и включена в файл виртуального хоста - не работает
Копирую и вставляю код в файл виртуального хоста, в серверный блок - снова не работает.
Есть ли какое-нибудь фактическое руководство по использованию плагина W3 Super Cache на сервере NGINX?
Ниже приведен мой файл nginx .conf :
user godadmin1337;
worker_processes 1;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 15;
types_hash_max_size 2048;
server_tokens off;
client_max_body_size 64m;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
add_header Strict-Transport-Security "max-age=31536000; includeSubdomains";
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
gzip_proxied any;
gzip_comp_level 2;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Cache Settings
##
fastcgi_cache_key "$scheme$request_method$host$request_uri";
add_header Fastcgi-Cache $upstream_cache_status;
##
# Security
##
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "origin-when-cross-origin" always;
#add_header Content-Security-Policy "default-src 'self';" always;
add_header X-Xss-Protection "1; mode=block" always;
##
# Cloudflare to real ip conversion
##
set_real_ip_from 103.21.244.0/22;
set_real_ip_from 103.22.200.0/22;
set_real_ip_from 103.31.4.0/22;
set_real_ip_from 104.16.0.0/12;
set_real_ip_from 108.162.192.0/18;
set_real_ip_from 131.0.72.0/22;
set_real_ip_from 141.101.64.0/18;
set_real_ip_from 162.158.0.0/15;
set_real_ip_from 172.64.0.0/13;
set_real_ip_from 173.245.48.0/20;
set_real_ip_from 188.114.96.0/20;
set_real_ip_from 190.93.240.0/20;
set_real_ip_from 197.234.240.0/22;
set_real_ip_from 198.41.128.0/17;
set_real_ip_from 2400:cb00::/32;
set_real_ip_from 2606:4700::/32;
set_real_ip_from 2803:f800::/32;
set_real_ip_from 2405:b500::/32;
set_real_ip_from 2405:8100::/32;
set_real_ip_from 2c0f:f248::/32;
set_real_ip_from 2a06:98c0::/29;
# use any of the following two
real_ip_header CF-Connecting-IP;
#real_ip_header X-Forwarded-For;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
#mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
#}
Мой виртуальный хост файл:
fastcgi_cache_path /home/godadmin1337/threepixelslab.gr/cache levels=1:2 keys_zone=threepixelslab.gr:100m inactive=60m;
server {
listen 80;
listen [::]:80;
server_name threepixelslab.gr www.threepixelslab.gr;
return 301 https://$server_name$request_uri;
}
server {
server_name builds.threepixelslab.gr;
return 301 https://threepixelsggglab.gr/proteinomena-gaming-pc-builds/;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name threepixelslab.gr www.threepixelslab.gr;
access_log /home/godadmin1337/threepixelslab.gr/logs/access.log;
error_log /home/godadmin1337/threepixelslab.gr/logs/error.log;
root /home/godadmin1337/threepixelslab.gr/public/;
index index.php;
ssl_certificate /etc/letsencrypt/live/threepixelslab.gr/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/threepixelslab.gr/privkey.pem; # managed by Certbot
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;
}
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
fastcgi_cache threepixelslab.gr;
fastcgi_cache_valid 60m;
}
location /xmlrpc.php {
deny all;
}
#location ~* ^/wp-content/uploads/.*.(html|htm|shtml|php|js|swf|css)$ {
# deny all;
#}
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires 365d;
access_log off;
}
location ~* \.(pdf|html|swf)$ {
expires 90d;
access_log off;
}
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires 90d;
add_header Cache-Control "public, no-transform";
}
}
И код, сгенерированный W3 Super Cache :
# BEGIN W3TC Page Cache cache
location ~ /wp-content/cache/page_enhanced.*gzip$ {
gzip off;
types {
text/xml xml_gzip;
}
default_type text/html;
add_header Content-Encoding gzip;
expires 3600s;
etag on;
if_modified_since exact;
add_header Pragma "public";
add_header Cache-Control "public";
add_header X-Powered-By "W3 Total Cache/0.13.3";
add_header Referrer-Policy "no-referrer-when-downgrade";
add_header Link "<$scheme://$host$request_uri>; rel=\"canonical\"";
}
# END W3TC Page Cache cache
# BEGIN W3TC Browser Cache
gzip on;
gzip_types text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/richtext text/plain text/xsd text/xsl text/xml image/bmp application/java application/msword application/vnd.ms-fontobject application/x-msdownload image/x-icon application/json application/vnd.ms-access video/webm application/vnd.ms-project application/x-font-otf application/vnd.ms-opentype application/vnd.oasis.opendocument.database application/vnd.oasis.opendocument.chart application/vnd.oasis.opendocument.formula application/vnd.oasis.opendocument.graphics application/vnd.oasis.opendocument.spreadsheet application/vnd.oasis.opendocument.text audio/ogg application/pdf application/vnd.ms-powerpoint image/svg+xml application/x-shockwave-flash image/tiff application/x-font-ttf audio/wav application/vnd.ms-write application/font-woff application/font-woff2 application/vnd.ms-excel;
location ~ \.(css|htc|less|js|js2|js3|js4)$ {
expires 31536000s;
etag on;
if_modified_since exact;
add_header Pragma "public";
add_header Cache-Control "public";
add_header X-Powered-By "W3 Total Cache/0.13.3";
add_header Referrer-Policy "no-referrer-when-downgrade";
add_header Link "<$scheme://$host$request_uri>; rel=\"canonical\"";
try_files $uri $uri/ /index.php?$args;
}
location ~ \.(html|htm|rtf|rtx|txt|xsd|xsl|xml)$ {
expires 3600s;
etag on;
if_modified_since exact;
add_header Pragma "public";
add_header Cache-Control "public";
add_header X-Powered-By "W3 Total Cache/0.13.3";
add_header Referrer-Policy "no-referrer-when-downgrade";
add_header Link "<$scheme://$host$request_uri>; rel=\"canonical\"";
try_files $uri $uri/ /index.php?$args;
}
location ~ \.(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|webp|json|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|webm|mpp|_otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|_ttf|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip)$ {
expires 31536000s;
etag on;
if_modified_since exact;
add_header Pragma "public";
add_header Cache-Control "public";
add_header X-Powered-By "W3 Total Cache/0.13.3";
add_header Referrer-Policy "no-referrer-when-downgrade";
add_header Link "<$scheme://$host$request_uri>; rel=\"canonical\"";
try_files $uri $uri/ /index.php?$args;
}
add_header Referrer-Policy "no-referrer-when-downgrade";
# END W3TC Browser Cache
# BEGIN W3TC CDN
add_header Link "<$scheme://$host$request_uri>; rel=\"canonical\"";
location ~ \.(ttf|ttc|otf|eot|woff|woff2|font.css)$ {
expires 31536000s;
etag on;
if_modified_since exact;
add_header Pragma "public";
add_header Cache-Control "public";
add_header X-Powered-By "W3 Total Cache/0.13.3";
add_header Referrer-Policy "no-referrer-when-downgrade";
add_header Link "<$scheme://$host$request_uri>; rel=\"canonical\"";
add_header Access-Control-Allow-Origin "*";
}
# END W3TC CDN
# BEGIN W3TC Page Cache core
set $w3tc_rewrite 1;
if ($request_method = POST) {
set $w3tc_rewrite 0;
}
if ($query_string != "") {
set $w3tc_rewrite 0;
}
if ($request_uri !~ \/$) {
set $w3tc_rewrite 0;
}
if ($http_cookie ~* "(comment_author|wp\-postpass|w3tc_logged_out|wordpress_logged_in|wptouch_switch_toggle)") {
set $w3tc_rewrite 0;
}
if ($http_user_agent ~* "(W3\ Total\ Cache)") {
set $w3tc_rewrite 0;
}
set $w3tc_ua "";
if ($http_user_agent ~* "((android|bb\d+|meego).+mobile|2.0\ mmp|240x320|\bppc\b|acer\ s100|alcatel|amoi|archos5|asus|au-mic|audiovox|avantgo|bada|benq|bird|blackberry|blazer|cdm|cellphone|cupcake|danger|ddipocket|docomo|docomo\ ht-03a|dopod|dream|elaine/3.0|ericsson|eudoraweb|fly|froyo|googlebot-mobile|haier|hiptop|hp.ipaq|htc|htc\ hero|htc\ magic|htc_dream|htc_magic|huawei|i-mobile|iemobile|iemobile/7|iemobile/7.0|iemobile/9|incognito|iphone|ipod|j-phone|kddi|konka|kwc|kyocera/wx310k|lenovo|lg|lg-gw620|lg/u990|lge\ vx|liquid\ build|maemo|midp|midp-2.0|mmef20|mmp|mobilephone|mot-mb200|mot-mb300|mot-v|motorola|msie\ 10.0|netfront|newgen|newt|nexus\ 7|nexus\ one|nintendo\ ds|nintendo\ wii|nitro|nokia|novarra|openweb|opera.mobi|opera\ mini|opera\ mobi|p160u|palm|panasonic|pantech|pdxgw|pg|philips|phone|playbook|playstation\ portable|portalmmm|proxinet|psp|qtek|s8000|sagem|samsung|samsung-s8000|sanyo|sch|sch-i800|sec|sendo|series60.*webkit|series60/5.0|sgh|sharp|sharp-tq-gx10|small|smartphone|softbank|sonyericsson|sonyericssone10|sonyericssonu20|sonyericssonx10|sph|symbian|symbian\ os|symbianos|t-mobile\ mytouch\ 3g|t-mobile\ opal|tattoo|toshiba|touch|treo|ts21i-10|up.browser|up.link|uts|vertu|vodafone|wap|webmate|webos|willcome|windows.ce|windows\ ce|winwap|xda|xoom|zte)") {
set $w3tc_ua _phones;
}
if ($http_user_agent ~* "(a1-32ab0|a210|a211|b6000-h|b8000-h|bnrv200|bntv400|darwin|gt-n8005|gt-p3105|gt-p6810|gt-p7510|hmj37|hp-tablet|hp\sslate|hp\sslatebook|ht7s3|ideatab_a1107|ideataba2109a|ideos\ss7|imm76d|ipad|k00f|kfjwi|kfot|kftt|kindle|l-06c|lg-f200k|lg-f200l|lg-f200s|m470bsa|m470bse|maxwell|me173x|mediapad|midc497|msi\senjoy\s10\splus|mz601|mz616|nexus|nookcolor|pg09410|pg41200|pmp5570c|pmp5588c|pocketbook|qmv7a|sgp311|sgpt12|shv-e230k|shw-m305w|shw-m380w|sm-p605|smarttab|sonysgp321|sph-p500|surfpad|tab07-200|tab10-201|tab465euk|tab474|tablet|tegranote|tf700t|thinkpad|viewpad|voltaire)") {
set $w3tc_ua _tablets;
}
set $w3tc_preview "";
if ($http_cookie ~* "(w3tc_preview)") {
set $w3tc_preview _preview;
}
set $w3tc_ssl "";
if ($scheme = https) {
set $w3tc_ssl _ssl;
}
if ($http_x_forwarded_proto = 'https') {
set $w3tc_ssl _ssl;
}
set $w3tc_enc "";
if ($http_accept_encoding ~ gzip) {
set $w3tc_enc _gzip;
}
set $w3tc_ext "";
if (-f "$document_root/wp-content/cache/page_enhanced/$http_host/$request_uri/_index$w3tc_ua$w3tc_ssl$w3tc_preview.html$w3tc_enc") {
set $w3tc_ext .html;
}
if (-f "$document_root/wp-content/cache/page_enhanced/$http_host/$request_uri/_index$w3tc_ua$w3tc_ssl$w3tc_preview.xml$w3tc_enc") {
set $w3tc_ext .xml;
}
if ($w3tc_ext = "") {
set $w3tc_rewrite 0;
}
if ($w3tc_rewrite = 1) {
rewrite .* "/wp-content/cache/page_enhanced/$http_host/$request_uri/_index$w3tc_ua$w3tc_ssl$w3tc_preview$w3tc_ext$w3tc_enc" last;
}
# END W3TC Page Cache core