Last active
June 6, 2018 22:30
-
-
Save VirtuBox/46bfe7ea735bb6d4fcafcb1bbdaa692c to your computer and use it in GitHub Desktop.
Nginx reverse-proxy with proxy_cache for WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=STATIC:75m inactive=24h max_size=8096m; | |
server { | |
server_name cdn.yourdomain.tld yourdomain.tld www.yourdomain.tld; | |
listen 443 ssl http2; | |
listen [::]:443 ssl http2; | |
ssl on; | |
ssl_certificate //path/to/ssl/yourdomain.tld/fullchain.pem; | |
ssl_certificate_key //path/to/ssl/yourdomain.tld/key.pem; | |
ssl_trusted_certificate //path/to/ssl/yourdomain.tld/cert.pem; | |
access_log /var/log/nginx/yourdomain.tld.access.log rt_cache; | |
error_log /var/log/nginx/yourdomain.tld.error.log; | |
proxy_read_timeout 3000; | |
set $no_cache ""; | |
if ($request_uri ~* "/wp-admin/") { | |
set $no_cache 1; | |
} | |
# Do not bypass if it's a POST request | |
if ($request_method = POST) { | |
set $no_cache 1; | |
} | |
if ($http_cookie ~* "(wordpress_logged_in_|wp\-postpass_|woocommerce_items_in_cart|woocommerce_cart_hash|wptouch_switch_toogle|comment_author_|comment_author_email_)") { | |
set $no_cache 1; | |
} | |
add_header X-Proxy-Cache $upstream_cache_status; | |
location / { | |
proxy_pass http://127.0.0.1:3000; | |
include proxy_params; | |
proxy_redirect off; | |
proxy_cache_key "$scheme$request_method$host$request_uri"; | |
proxy_cache STATIC; | |
proxy_no_cache $no_cache; | |
proxy_cache_bypass $no_cache; | |
proxy_cache_valid "60"; | |
proxy_cache_use_stale http_500 http_502 http_503 http_504 http_403 http_404 updating; | |
proxy_cache_background_update on; | |
sendfile on; | |
sendfile_max_chunk 5m; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment