Created
December 7, 2021 13:48
-
-
Save ianks/959c66f8921d4e1ab0f1c0764f801d2b to your computer and use it in GitHub Desktop.
WPEngine Reverse Proxy Nginx Config
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
user nginx; | |
worker_processes 10; | |
worker_rlimit_nofile 16384; | |
pid /var/run/nginx.pid; | |
error_log /var/log/nginx/error.log warn; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
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; | |
keepalive_timeout 65; | |
# compress the assets | |
gzip on; | |
gzip_proxied any; | |
server { | |
listen 80; | |
server_name blog-proxy; | |
location /_ping { | |
auth_basic off; | |
access_log off; | |
root /usr/share/nginx/html; | |
stub_status on; | |
} | |
resolver 8.8.8.8; | |
set $upstream_endpoint https://MY_WPENGINE_SUBDOMAIN.wpengine.com:443; | |
location /blog/ { | |
rewrite ^/blog/(.*) /$1 break; | |
# proxy the things | |
# https://www.poparide.com/blog/how-to-host-wpengine-blog-in-subdirectory-using-reverse-proxy/ | |
proxy_pass $upstream_endpoint; | |
proxy_set_header Host MY_WPENGINE_SUBDOMAIN.wpengine.com; | |
# strip /blog/ from the path | |
# hide a range of other, unimportant headers | |
proxy_hide_header link; | |
proxy_hide_header wpe-backend; | |
proxy_hide_header x-pingback; | |
# prevent forwarding of cookies | |
# proxy_set_header Cookie ""; | |
# prevent passing of WP cookie back to client | |
# proxy_hide_header Set-Cookie; | |
proxy_redirect https://floorhawk.wpengine.com/ https://www.MY_ACTUAL_DOMAIN.com/blog/; | |
proxy_redirect http://floorhawk.wpengine.com/ https://www.MY_ACTUAL_DOMAIN.com/blog/; | |
# for wp-admin | |
proxy_cookie_domain floorhawk.wpengine.com www.MY_ACTUAL_DOMAIN.com; | |
proxy_cookie_path / /blog/; | |
proxy_cookie_path ^/(.*) /blog/$1; | |
# to prevent wpengine from blocking our ips | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
# replace all instances of the WPEngine subdomain from the response | |
proxy_set_header Accept-Encoding ""; | |
sub_filter_types text/html text/css text/xml application/json; | |
sub_filter 'MY_WPENGINE_SUBDOMAIN.wpengine.com' 'www.MY_ACTUAL_DOMAIN.com/blog'; | |
sub_filter_once off; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment