Здравствуйте!
Переношу свой VPS от одного хостера к другому. С настройкой сервера сталкиваюсь крайне редко. Настроил, работает - забыл. Сервер используется как хост WordPress-сайтов. Конфигурация сервера: nginx + php-fpm + mysql. Также используется fastcgi_cache. Но новом сервере установил весь набор ПО, перенес конфиги со старого, запустил и nginx не стартует, ругается nginx: [emerg] unknown directive "fastcgi_cache_purge" in /etc/nginx/sites-enabled/site.ru:78.
На старом сервере стоит nginx 1.4.1, но новом 1.10.1. Не знаю важно ли это, но на новом сервере установил PHP7, пишут что есть прирост производительности, конфиги nginx обновил для PHP7.
В
документации nginx к директиве fastcgi_cache_purge есть приписка "функциональность доступна как часть коммерческой подписки." Неужели все дело в этом? Т.е. теперь без покупки подписки NGINX я не могу ничего сделать?
Конфиги:
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/*;
}
виртуальный хост conf:
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;
}