Skip to content

Instantly share code, notes, and snippets.

@alobato
Created March 24, 2015 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alobato/0d9b90a7a35d7b5fe511 to your computer and use it in GitHub Desktop.
Save alobato/0d9b90a7a35d7b5fe511 to your computer and use it in GitHub Desktop.
nginx_php_cache.conf
server {
server_name domain;
rewrite ^/(.*) http://www.domain/$1 permanent;
access_log /dev/null;
error_log /dev/null;
}
server {
server_name www.domain;
root /home/deployer/apps/appname/current;
index index.php;
client_max_body_size 30M;
error_log /home/deployer/apps/appname/shared/log/error.log;
access_log /home/deployer/apps/appname/shared/log/access.log;
location / {
# This line when enabled will use Nginx's gzip static module
gzip_static on;
# Disables serving gzip content to IE 6 or below
gzip_disable "MSIE [1-6]\.";
# Sets the default type to text/html so that gzipped content is served
# as html, instead of raw uninterpreted data.
default_type text/html;
# does the requested file exist exactly as it is? if yes, serve it and stop here
if (-f $request_filename) { break; }
# sets some variables to help test for the existence of a cached copy of the request
set $supercache_file '';
set $supercache_uri $request_uri;
# IF the request is a post, has a query attached, or a cookie
# then don't serve the cache (ie: users logged in, or posting comments)
if ($request_method = POST) { set $supercache_uri ''; }
if ($query_string) { set $supercache_uri ''; }
if ($http_cookie ~* "comment_author_|wordpress|wp-postpass_" ) {
set $supercache_uri '';
}
# if the supercache_uri variable hasn't been blanked by this point, attempt
# to set the name of the destination to the possible cache file
if ($supercache_uri ~ ^(.+)$) {
set $supercache_file /wp-content/cache/supercache/$http_host/$1index.html;
}
# If a cache file of that name exists, serve it directly
if (-f $document_root$supercache_file) { rewrite ^ $supercache_file break; }
# Otherwise send the request back to index.php for further processing
if (!-e $request_filename) { rewrite . /index.php last; }
# index index.html index.htm index.php;
# try_files $uri $uri/ /index.php?q=$request_uri;
# try_files $uri $uri/ /index.php?$args;
}
# Normally you do not need this if you are not using any error_page directive
# but having it off allows Wordpress to return it's own error page
# rather than the plain Nginx screen
fastcgi_intercept_errors off;
# Caching the typical static files such as css, js, jpg, png and so forth
# helps in telling the browser they can cache the content
location ~* \.(ico|css|js|gif|jpe?g|png)$ {
expires max;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# Most sites won't have configured favicon or robots.txt
# and since its always grabbed, turn it off in access log
# and turn off it's not-found error in the error log
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
# Rather than just denying .ht* in the config, why not deny
# access to all .invisible files
location ~ /\. { deny all; access_log off; log_not_found off; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment