Loading data/nginx.conf +4 −2 Original line number Diff line number Diff line Loading @@ -94,10 +94,12 @@ server { } } # limit the usefulness of malicious HTML/JS hosted in /media/ by serving # only media & common data files with their correct mime-type # Limit the usefulness of malicious HTML/JS hosted in /media/ by serving # only media & common data files with their correct mime-type. # Don't allow missing paths to be delegated to the PHP controller. location /media/ { root /app; try_files $uri =404; default_type application/octet-stream; types { # images # Loading plugins/media-url.php 0 → 100644 +40 −0 Original line number Diff line number Diff line <?php /** * Plugin Name: Media URL Fix * Plugin URI: https://code.kodo.org.uk/singing-chimes.co.uk/wordpress/tree/master/plugins * Description: Adjusts the media URL path base to /media, where the Nginx instance is hosting it. * Licence: MPL-2.0 * Licence URI: https://www.mozilla.org/en-US/MPL/2.0/ * Author: Dominik Sekotill * Author URI: https://code.kodo.org.uk/dom */ add_action( 'plugins_loaded', function() { add_filter( 'upload_dir', function( $paths ) { $baseurl = parse_url( $paths['baseurl'] ); $fullurl = parse_url( $paths['url'] ); $subdir = $paths['subdir']; $baseurl['path'] = '/media'; $fullurl['path'] = '/media' . ($subdir ? "/{$subdir}" : ''); $paths['baseurl'] = unparse_url( $baseurl ); $paths['url'] = unparse_url( $fullurl ); return $paths; }); }); function unparse_url( array $parts ) { return ( (isset($parts['scheme']) ? "{$parts['scheme']}://" : '') . (isset($parts['user']) ? $parts['user'] : '') . (isset($parts['pass']) ? ":{$parts['pass']}" : '') . (isset($parts['user'] || isset($parts['pass'])) ? '@' : '') . (isset($parts['host']) ? $parts['host'] : '') . (isset($parts['port']) ? ":{$parts['port']}" : '') . (isset($parts['path']) ? $parts['path'] : '') . (isset($parts['query']) ? "?{$parts['query']}" : '') . (isset($parts['fragment']) ? "#{$parts['fragment']}" : '') ); } scripts/entrypoint.sh +17 −3 Original line number Diff line number Diff line Loading @@ -165,15 +165,29 @@ setup_components() { return 0 } get_media_dir() { [[ -v MEDIA ]] && return MEDIA=$( wp config get UPLOADS --type=constant || wp option get upload_path ) [[ -n "${MEDIA}" ]] && return local _wp_content=$(wp config get WP_CONTENT_DIR --type=constant) MEDIA=${_wp_content:-wp-content}/uploads } setup_media() { # UID values change on every run, ensure the owner and group are set # correctly on ./media chown -R $WORKER_USER:$WORKER_USER ./media # correctly on the media directory/volume. get_media_dir chown -R ${WORKER_USER}:${WORKER_USER} "${MEDIA}" } collect_static() { get_media_dir local IFS=, declare -a flags=(flist stats remove del) test -t 1 && flags+=(progress2) Loading @@ -183,8 +197,8 @@ collect_static() --delete-delay \ --exclude-from=- \ --exclude='*.php' \ --exclude="${MEDIA}" \ --exclude=/static/ \ --exclude=/media/ \ --exclude=/vendor/ \ --force \ --info="${flags[*]}" \ Loading Loading
data/nginx.conf +4 −2 Original line number Diff line number Diff line Loading @@ -94,10 +94,12 @@ server { } } # limit the usefulness of malicious HTML/JS hosted in /media/ by serving # only media & common data files with their correct mime-type # Limit the usefulness of malicious HTML/JS hosted in /media/ by serving # only media & common data files with their correct mime-type. # Don't allow missing paths to be delegated to the PHP controller. location /media/ { root /app; try_files $uri =404; default_type application/octet-stream; types { # images # Loading
plugins/media-url.php 0 → 100644 +40 −0 Original line number Diff line number Diff line <?php /** * Plugin Name: Media URL Fix * Plugin URI: https://code.kodo.org.uk/singing-chimes.co.uk/wordpress/tree/master/plugins * Description: Adjusts the media URL path base to /media, where the Nginx instance is hosting it. * Licence: MPL-2.0 * Licence URI: https://www.mozilla.org/en-US/MPL/2.0/ * Author: Dominik Sekotill * Author URI: https://code.kodo.org.uk/dom */ add_action( 'plugins_loaded', function() { add_filter( 'upload_dir', function( $paths ) { $baseurl = parse_url( $paths['baseurl'] ); $fullurl = parse_url( $paths['url'] ); $subdir = $paths['subdir']; $baseurl['path'] = '/media'; $fullurl['path'] = '/media' . ($subdir ? "/{$subdir}" : ''); $paths['baseurl'] = unparse_url( $baseurl ); $paths['url'] = unparse_url( $fullurl ); return $paths; }); }); function unparse_url( array $parts ) { return ( (isset($parts['scheme']) ? "{$parts['scheme']}://" : '') . (isset($parts['user']) ? $parts['user'] : '') . (isset($parts['pass']) ? ":{$parts['pass']}" : '') . (isset($parts['user'] || isset($parts['pass'])) ? '@' : '') . (isset($parts['host']) ? $parts['host'] : '') . (isset($parts['port']) ? ":{$parts['port']}" : '') . (isset($parts['path']) ? $parts['path'] : '') . (isset($parts['query']) ? "?{$parts['query']}" : '') . (isset($parts['fragment']) ? "#{$parts['fragment']}" : '') ); }
scripts/entrypoint.sh +17 −3 Original line number Diff line number Diff line Loading @@ -165,15 +165,29 @@ setup_components() { return 0 } get_media_dir() { [[ -v MEDIA ]] && return MEDIA=$( wp config get UPLOADS --type=constant || wp option get upload_path ) [[ -n "${MEDIA}" ]] && return local _wp_content=$(wp config get WP_CONTENT_DIR --type=constant) MEDIA=${_wp_content:-wp-content}/uploads } setup_media() { # UID values change on every run, ensure the owner and group are set # correctly on ./media chown -R $WORKER_USER:$WORKER_USER ./media # correctly on the media directory/volume. get_media_dir chown -R ${WORKER_USER}:${WORKER_USER} "${MEDIA}" } collect_static() { get_media_dir local IFS=, declare -a flags=(flist stats remove del) test -t 1 && flags+=(progress2) Loading @@ -183,8 +197,8 @@ collect_static() --delete-delay \ --exclude-from=- \ --exclude='*.php' \ --exclude="${MEDIA}" \ --exclude=/static/ \ --exclude=/media/ \ --exclude=/vendor/ \ --force \ --info="${flags[*]}" \ Loading