Why?

There is much debate on the merits of hosting your blog at https://blog.examplecompany.com or https://examplecompany.com/blog.

It’s worth noting that WPEngine does not recommend this practiceSome people on the internet suggest there is no benefit to doing so. Others suggest otherwise.

For those that want to host at https://site.com/blog and do it with a managed WordPress hosting provider like WPEngine, this article is for you.

(Note, WPEngine will automatically block your reverse proxy, so you will need to contact customer support and ask them to whitelist its IP address in their firewall. I found this to be a painless process thanks to the friendly support staff at WPEngine.)

How?

The trick to getting the blog to look like it’s living on the main site (but actually living elsewhere) is to use a reverse proxy.

HAProxy is a powerful reverse proxy, though its configuration has a bit of a learning curve compared to Nginx or Apache.

We use HAProxy internally because it works well with AWS Elastic Load Balancers, which frequently change their IP address. Learn more

HAProxy config

frontend ssl_in
  bind *:443 ssl crt /etc/haproxy/website.com.combined
  acl root path /
  acl blog path_beg /blog
  acl leasopedia path_beg /leasopedia
  acl glossary path_beg /glossary
  acl wpadmin path_beg /wp-
  acl blog_search query -m reg ^s=.*$
  acl blog_preview query -m reg ^p=.*$

  use_backend wpengine if blog OR leasopedia OR glossary OR wpadmin OR root blog_search OR root blog_preview
  default_backend main-site

backend wpengine
  server wpengine examplecompany.wpengine.com:443 ssl ca-file /etc/ssl/certs/ca-certificates.crt

backend main-site
  server main-site example.examplecompany.com.:443 ssl ca-file /etc/ssl/certs/ca-certificates.crt
bind *:443 ssl crt /etc/haproxy/website.com.combined

You’ll need to use SSL, as all WPEngine installs redirect to SSL.

Of note is that HAProxy expects your certificate chain and your private key to be combined into one file

acl

These are the pattern matching lines that we’ll use to determine which traffic is forwarded to WPEngine

use_backend wpengine if blog OR leasopedia OR glossary OR wpadmin OR root blog_search OR root blog_preview

This directs /blog*, /leasopedia*, /glossary* and /wp-* to WPEngine.

You can replace these with your own blog and page paths configured in wordpress.

This line also directs /?s= and /?p= to wordpress using the combined root and blog_search and blog_preview lines.

These are necessary to making searching and page previews work in WordPress.

default_backend main-site

Everything that doesn’t match one of the above patterns will go to the main site.

backend wpengine

Directives in the frontend that resolve to this backed will route to the blog.

backend main-site

Directives in the frontend that resolve to this backed will route to your main site.

See it live

I hope you found this useful — and check out the results!