Fatal error in wp-admin/customize.php after fresh install due to null $wp_customize

It seems I got some faulty nginx configuration from an article on how to configure WordPress in a subdirectory.

Config Before

location @wp {
    rewrite ^/blog(.*) /blog/index.php?q=$1;
}

location ^~ /blog {
    root /home/user;
    index index.php index.html index.htm;
    try_files $uri $uri/ @wp;

    location ~ \.php$ {

        include fastcgi_params;

        fastcgi_index index.php;
        fastcgi_intercept_errors on;
        # Deleted this line
        fastcgi_split_path_info ^(/blog)(/.*)$;
        fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
    }
    break;
}

Config After

location @wp {
    rewrite ^/blog(.*) /blog/index.php?q=$1;
}

location ^~ /blog {
    root /home/user;
    index index.php index.html index.htm;
    try_files $uri $uri/ @wp;

    location ~ \.php$ {

        include fastcgi_params;

        # Added this line
        fastcgi_param SCRIPT_FILENAME $request_filename;
        fastcgi_index index.php;
        fastcgi_intercept_errors on;
        fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
    }
    break;
}

As mentioned in some comments, some PHP Server variables were incorrectly set due to a faulty nginx configuration causing issues when loading /wp-admin/customize.php

You can confirm your nginx configuration is faulty for this scenario if you visit /wp-admin/customize.php?wp_customize=on and it starts to work instead of throwing a fatal error.

tech