Welcome! Log In Create A New Profile

Advanced

Enabling caching for PHP

Posted by allyunion 
Enabling caching for PHP
March 10, 2012 05:52PM
Hi,

When the caching in the fastcgi parameters are active, site users are directed elsewhere (not to the site). I think there is a conflict with the set $cache_uri directive. Though for some reason when the $cache_uri options are commented out, the site doesn't work at all.

server {
listen *:80;
index index.php index.html index.htm;

server_name www.example.com
set $cache_uri $request_uri;

if ($request_method = POST) {
set $cache_uri 'no cache';
}

if ($query_string != "") {
set $cache_uri 'no cache';
}

if ($request_method !~ ^(GET|HEAD|POST)$ ) {
return 444;
}

error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /favicon.ico {
log_not_found off;
access_log off;
}

location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}

# Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
location ~* /files(/.*)? {
access_log off;
expires max;

rewrite ^(.*\.[^./]+).+\.[^.]+$ $1;
}
location / {
if ($uri ~* ^/(images|css|themes|files)) {
access_log off;
expires max;
break;
}
if ($uri !~ ^/index\.php) {
rewrite ^/(.*)$ /index.php/$1 last;
}

try_files $uri $uri/ /index.php?q=$uri =404;
}

# Pass all .php files onto a php-fpm/php-fcgi server.
location ~ ^.+\.php {
fastcgi_index index.php;
fastcgi_pass unix:php5-fpm.sock;

# Caching -- NOT WORKING SECTION
############################################################
# fastcgi_cache DEFAULT;
# fastcgi_cache_valid 200 302 1h;
# fastcgi_cache_valid 301 1d;
# fastcgi_cache_valid any 1m;
# fastcgi_cache_min_uses 1;
# fastcgi_cache_use_stale error timeout invalid_header http_500;
############################################################

set $path_info $fastcgi_script_name;

if ($uri ~ '\.php(/.*)$') {
set $path_info $1;
}

if ($scheme = 'https') {
set $fastcgi_https on;
}

if ($scheme = 'http') {
set $fastcgi_https off;
}
fastcgi_param HTTPS $fastcgi_https;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;

include fastcgi_params;
}

# Directives to send expires headers and turn off 404 error logging.
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svgz?|tff|otf)$ {
expires max;
log_not_found off;
access_log off;
}

}
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 160
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