Skip to content

Instantly share code, notes, and snippets.

@joestump
Created December 7, 2009 17:15
Show Gist options
  • Save joestump/250941 to your computer and use it in GitHub Desktop.
Save joestump/250941 to your computer and use it in GitHub Desktop.
server {
listen 80;
server_name stu.mp;
# if the request uri was a directory, store the index page name
if ($request_uri ~ /$) {
set $store_extra index.html;
}
# proxy module defaults
proxy_store_access user:rw group:rw all:r;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
# if a precompiled gzip of the file exists, use it and force http proxies
# to use separate cache's based on User-Agent
# gzip_vary on;
# gzip_static on;
location / {
root /var/www/${host}/cache;
index index.html;
# set the location the proxy will store the data to. Add the index page
# name if the uri was a directory (nginx can't normally store these)
proxy_store $document_root${request_uri}${store_extra};
# go through the proxy if there is no cache
if (!-f $document_root${request_uri}${store_extra}) {
proxy_pass http://localhost:8080;
}
# workaround. headers module doesn't take into account proxy response
# headers. It overwrites the proxy Cache-Control header, causing
# private/no-cache/no-store to be wiped, so only set if not using proxy
if (-f $document_root${request_uri}${store_extra}) {
expires 0;
}
}
# don't cache admin folder, send all requests through the proxy
location /wp-admin {
proxy_pass http://localhost:8080;
}
# handle static files directly. Set their expiry time to max, so they'll
# always use the browser cache after first request
location ~* (css|js|png|jpe?g|gif|ico)$ {
root /var/www/${host}/html;
expires max;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment