How to serve a WordPress blog at /blog/ with Nginx?
<p>All my attempts to Google "host wordpress on subdirectory" seem to be about moving the Wordpress installation to a subdirectory while still serving it from <code>/</code>. I want to serve it at <code>/blog/</code>.</p>

<p>I have one docker image running Nginx and another serving Wordpress via php-fpm. I updated <code>siteurl</code> in the wp_options table to be <a href="http://example.com/blog" rel="nofollow">http://example.com/blog</a> and finally got the index page to show up, but all the related assets give a 403 error. I though it might have to do with a rewrite directive in my Nginx conf, so I tried removing <code>rewrite ^/blog/(.*) /$1  break;</code>, but that then caused <code>/blog</code> to return 404.</p>

<p>Here's the relevant portion of my Nginx conf:</p>

<pre><code>location /blog/ {
    resolver ${RESOLVER_IP};
    set $wordpress_host "${WORDPRESS_SERVICE_HOST}";
    rewrite ^/blog/(.*) /$1  break;


    fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
    fastcgi_param  SERVER_SOFTWARE    nginx;
    fastcgi_param  QUERY_STRING       $query_string;
    fastcgi_param  REQUEST_METHOD     $request_method;
    fastcgi_param  CONTENT_TYPE       $content_type;
    fastcgi_param  CONTENT_LENGTH     $content_length;
    fastcgi_param  SCRIPT_FILENAME    /srv$fastcgi_script_name;
    fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
    fastcgi_param  REQUEST_URI        $document_uri;
    fastcgi_param  DOCUMENT_URI       $document_uri;
    fastcgi_param  DOCUMENT_ROOT      /srv;
    fastcgi_param  SERVER_PROTOCOL    $server_protocol;
    fastcgi_param  REMOTE_ADDR        $remote_addr;
    fastcgi_param  REMOTE_PORT        $remote_port;
    fastcgi_param  SERVER_ADDR        $server_addr;
    fastcgi_param  SERVER_PORT        $server_port;
    fastcgi_param  SERVER_NAME        $server_name;

    fastcgi_param HTTP_X_REAL_IP $remote_addr;
    fastcgi_param HTTP_X_FORWARDED_FOR $proxy_add_x_forwarded_for;
    fastcgi_param HTTP_X_FORWARDED_HOST $http_host;
    fastcgi_param HTTP_X_FORWARDED_PROTO $real_scheme;
    fastcgi_param HTTP_HOST $http_host;
    # requests gzipped content from php. gunzip is used for clients that
    # can't accept gzip.
    fastcgi_param HTTP_ACCEPT_ENCODING "gzip";
    fastcgi_param HTTP_X_PREFERRED_TYPE $preferred_type;
    fastcgi_read_timeout 60;
    fastcgi_next_upstream error timeout http_500 http_503;
    fastcgi_buffers 16 64k;
    # specifies buffer used for HTTP headers, doesn't need to be large
    fastcgi_buffer_size 2k;
    fastcgi_temp_file_write_size 64k;
    fastcgi_pass $wordpress_host:80;
    fastcgi_index index.php;
    #echo '';


    add_header X-document_root $document_root;
    add_header X-fastcgi_script_name $fastcgi_script_name;
    add_header X-request_uri $request_uri;
    add_header X-document_uri $document_uri;
}
</code></pre>