Skip to content

Instantly share code, notes, and snippets.

@danivovich
Created June 24, 2016 13:18
Show Gist options
  • Save danivovich/50b2745f82ec154b7080c3d70f3b1dbb to your computer and use it in GitHub Desktop.
Save danivovich/50b2745f82ec154b7080c3d70f3b1dbb to your computer and use it in GitHub Desktop.
Basic nginx configuration for a caching proxy for ghost blogging, designed for use in Docker
server {
listen 80 default_server;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
location ~* \.(jpg|jpeg|svg|png|gif|ico|css|js|eot|woff)$ {
proxy_cache GHOST;
proxy_cache_valid 200 1d;
proxy_cache_valid 404 5m;
proxy_ignore_headers "Cache-Control";
access_log off;
expires 1d;
proxy_pass http://ghost_blog;
}
location ~ ^/(?:ghost) {
expires 0;
add_header Cache-Control "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0";
proxy_pass http://ghost_blog;
}
location ~ ^/(?:p/) {
expires 0;
add_header Cache-Control "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0";
proxy_pass http://ghost_blog;
}
location / {
proxy_cache GHOST;
proxy_cache_valid 200 1h;
proxy_cache_valid 404 5m;
proxy_ignore_headers "Set-Cookie";
proxy_hide_header "Set-Cookie";
proxy_ignore_headers "Cache-Control";
proxy_hide_header "Cache-Control";
proxy_hide_header "Etag";
expires 30m;
proxy_pass http://ghost_blog;
}
}
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile off;
keepalive_timeout 65;
gzip on;
gzip_disable "MSIE [1-6]\.";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_min_length 1000;
gzip_buffers 16 128k;
gzip_http_version 1.0;
gzip_types image/svg+xml text/plain text/css application/json application/x-javascript application/javascript text/xml application/xml application/xml+rss text/javascript text/x-component font/truetype font/opentype;
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=GHOST:100m inactive=24h max_size=2g;
proxy_cache_key "$scheme$host$request_uri";
proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
proxy_http_version 1.1;
add_header X-Cache $upstream_cache_status;
upstream ghost_blog {
server ghost:2368;
}
include /etc/nginx/server-*.conf;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment