Last active
August 20, 2019 10:49
-
-
Save lukeburden/e90812f65f548bf13610fc9b61ef6a08 to your computer and use it in GitHub Desktop.
Nginx Reverse Proxy for Wordpress with Caching
This file contains 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/nginx/cache levels=1:2 keys_zone=blog_cache:1m max_size=100m inactive=60m use_temp_path=off; | |
server{ | |
listen 80; | |
server_name example.com; | |
# prevent forwarding of cookies | |
proxy_set_header Cookie ""; | |
# prevent passing of WP cookie back to client | |
proxy_hide_header Set-Cookie; | |
# hide a range of other, unimportant headers | |
proxy_hide_header link; | |
proxy_hide_header wpe-backend; | |
proxy_hide_header x-pingback; | |
location /blog/ { | |
proxy_pass https://exampleblog.wpengine.com:443/; | |
proxy_set_header Host exampleblog.wpengine.com; | |
# strip /blog/ from the path | |
rewrite /blog/(.*) /$1 break; | |
# replace all instances of the WPEngine subdomain from the response | |
subs_filter_types text/html text/css text/xml; | |
subs_filter 'exampleblog.wpengine.com' 'example.com/blog' gi; | |
} | |
# we cache all content for 60 minutes, ignoring WPEngine cache | |
# headers but not caching most errors | |
proxy_cache blog_cache; | |
proxy_ignore_headers Cache-Control; | |
proxy_cache_valid 200 302 60m; | |
proxy_cache_valid 404 10m; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment