Welcome! Log In Create A New Profile

Advanced

Fastcgi_cache only caching 1 website

October 14, 2016 12:11PM
Hi,

Im relativly new to the Linux world but am learning bloody quick (you have too, its unforgiving! :) )

I am setting up a new web server and im nearly ready to go live but cant iron out 1 last issue - and thats i have multiple wordpress websites setup.

Each wordpress website has its own install and installation directory and seperate database.

I have configured nginx with the fastcgi_cache module and it works - but only for the very first website i setup on the server. Every subsequent website gets nothing cached.

Running nginx/php7 on Ubuntu Server 16.04

Here is my nginx/nginx.conf file

user www-data;
worker_processes 1;
worker_rlimit_nofile 100000;
pid /run/nginx.pid;

events {
worker_connections 1024;
multi_accept on;
}

http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 15;
types_hash_max_size 2048;

server_tokens off;
reset_timedout_connection on;
# add_header X-Powered-By "EasyEngine";
add_header rt-Fastcgi-Cache $upstream_cache_status;

# Limit Request
limit_req_status 403;
limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;

# Proxy Settings
# set_real_ip_from proxy-server-ip;
# real_ip_header X-Forwarded-For;

fastcgi_read_timeout 300;
client_max_body_size 100m;

##
# SSL Settings
##

ssl_session_cache shared:SSL:20m;
ssl_session_timeout 10m;
ssl_prefer_server_ciphers on;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:ECDHE-RSA-DES-CBC3-SHA:ECDHE-ECDSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

##
# Basic Settings
##
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;

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

##
# Logging Settings
##

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

# Log format Settings
log_format rt_cache '$remote_addr $upstream_response_time $upstream_cache_status [$time_local] '
'$http_host "$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent"';

##
# 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
application/atom+xml
application/javascript
application/json
application/rss+xml
application/vnd.ms-fontobject
application/x-font-ttf
application/x-web-app-manifest+json
application/xhtml+xml
application/xml
font/opentype
image/svg+xml
image/x-icon
text/css
text/plain
text/x-component
text/xml
text/javascript;

##
# Cache Settings
##

add_header Fastcgi-Cache $upstream_cache_status;
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;

##
# Virtual Host Configs
##

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;

server {
listen 80 default_server;
server_name _;
return 444;
}

}

Here is the cache working websites config

fastcgi_cache_path /var/www/html/1stwebsite.com/cache levels=1:2 keys_zone=1stwebsite.com:100m inactive=60m;

server {
server_name 1stwebsite.com www.1stwebsite.com;


access_log /var/www/html/1stwebsite.com/logs/access.log;
error_log /var/www/html/1stwebsite.com/logs/error.log;

root /var/www/html/1stwebsite.com/public/;
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/|/phpmyadmin|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {
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 ($http_cookie ~* "PHPSESSID"){
set $skip_cache 1;
}

location / {
try_files $uri $uri/ /index.php?$args;
}

location /phpmyadmin {
auth_basic "Admin Login";
auth_basic_user_file /etc/nginx/allow_phpmyadmin;
}

location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
fastcgi_cache 1stwebsite.com;
fastcgi_cache_valid 60m;
}

location ~ /purge(/.*) {
fastcgi_cache_purge 1stwebsite.com "$scheme$request_method$host$1";
}

}


Here is 1 of the non working cache websites config

fastcgi_cache_path /var/www/html/2ndwebiste.co.uk/cache levels=1:2 keys_zone=2ndwebiste.co.uk:100m inactive=60m;

server {
server_name 2ndwebiste.co.uk www.2ndwebiste.co.uk;


access_log /var/www/html/2ndwebiste.co.uk/logs/access.log;
error_log /var/www/html/2ndwebiste.co.uk/logs/error.log;

root /var/www/html/2ndwebiste.co.uk/public/;
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/|/phpmyadmin|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {
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 ($http_cookie ~* "PHPSESSID"){
set $skip_cache 1;
}

location / {
try_files $uri $uri/ /index.php?$args;
}

location /phpmyadmin {
auth_basic "Admin Login";
auth_basic_user_file /etc/nginx/allow_phpmyadmin;
}

location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
fastcgi_cache 2ndwebiste.co.uk;
fastcgi_cache_valid 60m;
}

location ~ /purge(/.*) {
fastcgi_cache_purge 2ndwebiste.co.uk "$scheme$request_method$host$1";
}

}


I think its to do with the very top line of both config files?

fastcgi_cache_path /var/www/html/2ndwebiste.co.uk/cache levels=1:2 keys_zone=2ndwebiste.co.uk:100m inactive=60m;

Does this need to be in the main nginx.conf file and not in each individual website config?

If so - am i not meant to have a cache folder for each individual website, should there just be 1 central cache folder for all websites?
I thought the "keys_zone" directive needs to be individual for each website, and thus created a seperate cache location for each website hosted.

Thanks to anybody that can walk with me over the finishing line

Regards
Subject Author Posted

Fastcgi_cache only caching 1 website

mrast October 14, 2016 12:11PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 278
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready