Answer the question
In order to leave comments, you need to log in
How to fix nginx error: unknown directive "fastcgi_cache_purge"?
Hello!
I am moving my VPS from one host to another. I rarely encounter server settings. Configured, works - forgot. The server is used as a host for WordPress sites. Server config: nginx + php-fpm + mysql. Also used is fastcgi_cache. But the new server installed the entire set of software, transferred the configs from the old one, launched and nginx does not start, nginx swears: [emerg] unknown directive "fastcgi_cache_purge" in /etc/nginx/sites-enabled/site.ru:78.
The old server has nginx 1.4.1, but the new one has 1.10.1. I don’t know if this is important, but I installed PHP7 on the new server, they write that there is a performance increase, I updated the nginx configs for PHP7.
In the nginx documentationthe fastcgi_cache_purge directive has a postscript "functionality is available as part of a commercial subscription." Is it all about this? Those. now without buying an NGINX subscription I can't do anything?
Configs:
nginx.conf
user www-data;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 768;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
client_max_body_size 20M;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
server_tokens off;
#Limit Request
limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;
limit_req_status 444;
server_names_hash_bucket_size 64;
#Gzip settings
gzip on;
gzip_disable "msie6";
gzip_types text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon;
#gzip_vary on;
gzip_proxied any;
gzip_min_length 1100;
gzip_comp_level 3;
gzip_buffers 16 8k;
gzip_http_version 1.0;
#gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
#Wordpress Cache
fastcgi_cache_path /home/server/nginx-cache levels=1:2 keys_zone=WORDPRESS:10m inactive=30m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
fastcgi_cache_use_stale error timeout invalid_header http_500;
# include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
server {
listen 80;
server_name example.com www.example.com;
root /home/server/htdocs/example.com/www;
access_log /home/server/logs/example.com/nginx.access.log;
error_log /home/server/logs/example.com/nginx.error.log;
index index.php index.html index.htm;
location ~ \wp-login.php {
auth_basic "Unauthorized";
auth_basic_user_file /home/server/.htpasswd;
#deny all;
#allow 109.184.54.20;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
include fastcgi_params;
}
#Enable Browser Cache
location ~* \.(jpg|jpeg|gif|png|ico|css|pdf|ppt|txt|bmp|rtf|js)$ {
access_log off;
expires 30d;
#add_header Pragma public;
#add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
#Block HotLink
location ~ \.(jpeg|png|gif|jpg)$ {
valid_referers none blocked example.com *.example.com;
if ($invalid_referer) {
return 403;
}
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /etc/nginx/error;
}
#Nginx Helper
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-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.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 ~ .php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_pass unix://run/php/php7.0-fpm.sock;
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
fastcgi_index index.php;
fastcgi_cache WORDPRESS;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
fastcgi_cache_valid 200 301 202 404 60m;
}
location ~ /purge(/.*) {
fastcgi_cache_purge WORDPRESS "$scheme$request_method$host$1";
}
#WORDPRESS conf
location / {
try_files $uri $uri/ /index.php?$args;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~ /\. {
deny all;
}
location ~* /(?:uploads|files)/.*\.php$ {
deny all;
}
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
}
Answer the question
In order to leave comments, you need to log in
Yes. Exactly. This functionality is only available in the paid version. As if the nginx developers also want to earn.
Older versions could be built with a free module https://github.com/FRiCKLE/ngx_cache_purge
It gave such functionality.
While I see one thing, you specified the WORDPRES zone, and you are requesting WORDPRESS
If there is no money for a paid version of nginx, then you can do something like this:
if ($http_purgecache = 1){
set $skip_cache 1;
set $skip_cache_save 0;
}
#In the php processing section
#cache
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache_save;
fastcgi_cache WORDPRESS;
fastcgi_cache_valid 1m;
location ~ /purgecache(/.*) {
proxy_set_header purgecache 1;
proxy_set_header Host $host;
proxy_pass $scheme://IP:PORT$1;
# fastcgi_cache_purge WORDPRESS "$scheme$request_method$host$1";
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question