How can WordPress be made to live at /blog, while another application handles the root directory /, using nginx?

I have the ordinary subdomain setup right now, which works fine.

I've read https://codex.wordpress.org/Nginx and changed my config according to serving WordPress as a subdirectory. In wp-config.php I have


but I keep getting 404 errors, or WordPress not loading CSS files. I've also tried

location /blog {
  try_files /var/www/wordpress/$uri /var/www/wordpress/$uri/ /blog/index.php?$args;

404s again.

This must be an FAQ, but I haven't nailed the search terms for it (/blog being so common doesn't help).

Where can I find a full nginx config file and wp-config settings that have WordPress live at /blog? Do I need to alter any WP settings in its MySQL database?


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:


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.