Skip to content

Instantly share code, notes, and snippets.

@muriloazevedo
Forked from farandal/gist:5923317
Created September 13, 2014 23:28
Show Gist options
  • Save muriloazevedo/e4a5d5576f109c625cbb to your computer and use it in GitHub Desktop.
Save muriloazevedo/e4a5d5576f109c625cbb to your computer and use it in GitHub Desktop.
Config for nginx work with thumbs
#Attention!, this scripts needs a modified version of timthumb you'll find in my git account.
#Francisco Aranda, Developer, Software Architect and Enterpreneur, Chile.
#http://farandal.com
#http://www.git.com/farandal
location ~ /thumb/.*\.(png|jpg)$ {
#set $domain yourdomain.com; # Change this to your site's domain name, you may or not need to uncomment this.
set $root_fcgi /home/user/public_html/yourdomain.com/public; # Change this to the public root folder of your site
set $root_cache $root_fcgi/thumb; # Change this to a folder in which to cache the minified files
set $thumb_dir /home/ligasams/public_html/vendor/timthumb-read-only; # Change this folder to wherever you put or cloned the timthumb repository. it's not necesary that timthumb be in a public access folder, the calls to the script will be managed by nginx
include fastcgi_params;
fastcgi_param SITE_ROOT $root_fcgi;
fastcgi_param SCRIPT_FILENAME $thumb_dir/timthumb.php;
fastcgi_param PATH_INFO timthumb.php;
#fastcgi_param SERVER_NAME $domain; # you may or not need to uncomment this.
fastcgi_param CACHE_DIR $root_cache;
root $root_cache;
expires max;
gzip_static on; # You will need to have installed Nginx using the --with-http_gzip_static_module flag for this to work
gzip_http_version 1.1;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
gzip_vary on;
# If there is not already a cached copy, create one, but if the thumb file exists makes a simple request directly to the cached file.
if (!-f $request_filename) {
root $root_fcgi;
fastcgi_pass 127.0.0.1:49232; #Or whatever port you have configured
}
#I'd recommend to use cloudfront from now on to serve the static cached thumbnails ;-)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment