Skip to content

Instantly share code, notes, and snippets.

@perusio
Created October 16, 2011 02:52
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 perusio/1290446 to your computer and use it in GitHub Desktop.
Save perusio/1290446 to your computer and use it in GitHub Desktop.
Example microcache configuration
## Declare cache zone.
fastcgi_cache_path /opt/local/var/cache/nginx levels=1:2 keys_zone=microcache:5m max_size=1G;
map $http_cookie $no_cache {
default 0;
~_mcnc 1;
}
server {
listen 80;
server_name local.domain.co.uk;
access_log /opt/local/var/log/nginx/domain.co.uk.access.log;
error_log /opt/local/var/log/nginx/domain.co.uk.error.log debug;
rewrite_log on;
root /data/local.domain.co.uk/app_emorsgateseeds/webroot;
index index.php index.html index.htm;
client_max_body_size 20m;
# Not found this on disk?
# Feed to CakePHP for further processing!
location / {
try_files $uri $uri/ /index.php?url=$uri;
}
## This kind of config is "insecure" a bad habit from Apache that gets propagated on Nginx.
## Try location = /index.php and see if it works.
location ~ \.php$ {
fastcgi_read_timeout 200;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_intercept_errors on; # to support 404s for PHP files not found
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /opt/local/etc/nginx/fastcgi_params;
fastcgi_cache microcache;
fastcgi_cache_bypass $no_cache;
fastcgi_no_cache $no_cache;
fastcgi_cache_key $scheme$host$request_method$request_uri;
fastcgi_cache_valid 200 302 1h;
fastcgi_cache_valid 301 1d;
fastcgi_cache_valid any 1m;
fastcgi_cache_use_stale updating error timeout invalid_header http_500;
}
# Static files.
# Set expire headers, Turn off access log.
## Do you need a regex here? Can't you use an exact location? = /favicon.ico?
location ~* \favicon.ico$ {
access_log off;
expires 1d;
add_header Cache-Control public;
}
location ~ ^/(?:img|js|css|cjs|ccss)/ {
access_log off;
expires max;
add_header Cache-Control public;
}
# Deny access to .htaccess files,
# git & svn repositories, etc
location ~ /\.(?:ht|git|svn) {
deny all;
}
}
@vitaoloureiro
Copy link

How to cache a mobile version of my site if i'm using the same url for both?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment