# sets the proxy cache path location, max size 2g
proxy_cache_path /etc/nginx/cache levels=1:2 keys_zone=STATIC:100m inactive=24h max_size=2g;
# transfers the `Host` header to the backend
proxy_set_header Host $host;
# uses the defined STATIC cache zone
proxy_cache STATIC;
# cache 200 10 minutes, 404 1 minute, others status codes not cached
proxy_cache_valid 200 10m;
proxy_cache_valid 404 1m;
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;
# transfers real client IP to your ghost app,
# otherwise you would see your server ip
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 20m;
client_body_buffer_size 128k;
# default expires (browser cache) set to 1 minute
expires 1m;
# gzip every proxied responses
gzip_proxied any;
# gzip only if user asks it
gzip_vary on;
# gzip only theses mime types
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript application/json application/javascript;
gzip_static on;
# add a cache HIT/MISS header
add_header X-Cache $upstream_cache_status;
# do not show incoming Etags, if-modified-since is sufficient
proxy_hide_header Etag;
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.html index.htm;
client_max_body_size 10G;
pagespeed on;
pagespeed RewriteLevel CoreFilters;
pagespeed EnableFilters move_css_above_scripts,defer_javascript,lazyload_images;
pagespeed EnableFilters prioritize_critical_css;
pagespeed UseExperimentalJsMinifier on;
pagespeed EnableFilters inline_google_font_css;
pagespeed EnableFilters insert_dns_prefetch;
location / {
proxy_cache STATIC;
proxy_cache_valid 200 30m;
proxy_cache_valid 404 1m;
proxy_ignore_headers X-Accel-Expires Expires Cache-Control;
proxy_ignore_headers Set-Cookie;
proxy_hide_header Set-Cookie;
proxy_hide_header X-powered-by;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
rewrite "\d{4}\/\d{2}\/\d{2}\/([^.]+)(.*)$" /$1$2 permanent;
rewrite ^(/wp-content/)(.*)$ /old/$2 permanent;
expires 10m;
}
location /content/images {
alias /var/www/ghost/content/images;
access_log off;
expires max;
}
location /old {
alias /var/www/ghost/content/old;
access_log off;
expires max;
}
location /assets {
alias /var/www/ghost/content/themes/lechuck/assets;
access_log off;
expires max;
}
location /public {
alias /var/www/ghost/core/built/public;
access_log off;
expires max;
}
location /ghost/scripts {
alias /var/www/ghost/core/built/scripts;
access_log off;
expires max;
}
location ~ ^/(?:ghost|signout) {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
add_header Cache-Control "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0";
}
}
upstream ghost {
server localhost:2368;
keepalive 64;
}