How can I have nginx serve WordPress at /blog?

Here’s what mostly works:

  1. Have an nginx config file for the subdomain setup, and ensure that http://wordpress.example.com works.

  2. In the nginx default config, have a location block for /blog that proxies to the subdomain:

    location /blog {
        rewrite ^/blog(/?.*)$ $1 break;  # remove "/blog"
        proxy_set_header Host wordpress.example.com;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass http://wordpress.example.com;
    }
    
  3. In wp-config.php, have:

    define('WP_HOME','http://idorecall.com/blig');
    define('WP_SITEURL','http://idorecall.com/blig');
    

I’m saying this “mostly” works because:

  • Some page elements may not be loading. For example, the icomoon icons used by the Avada theme in the footer don’t show up.
  • If you access your /blog URL via https, e.g. at http://example.com/blog, but the wordpress subdomain config uses http, browsers will refuse to load many resources, with a “Mixed Content” warning. One solution is to enable HTTPS on the subdomain too (StartSSL has a certificate with one free subdomain). Another, I suspect, is that you’ll have to run a WordPress database search and replace of http://wordpress.example.com with http://example.com/blog.
  • There’s an extra request involved with proxy_passing.