diff --git a/bitnami/wordpress-nginx/6/debian-11/rootfs/opt/bitnami/scripts/libwordpress.sh b/bitnami/wordpress-nginx/6/debian-11/rootfs/opt/bitnami/scripts/libwordpress.sh index 30e65d56d14c..fb50bb2e6fd5 100644 --- a/bitnami/wordpress-nginx/6/debian-11/rootfs/opt/bitnami/scripts/libwordpress.sh +++ b/bitnami/wordpress-nginx/6/debian-11/rootfs/opt/bitnami/scripts/libwordpress.sh @@ -89,6 +89,7 @@ wordpress_validate() { check_yes_no_value "WORDPRESS_RESET_DATA_PERMISSIONS" check_yes_no_value "WORDPRESS_SKIP_BOOTSTRAP" check_multi_value "WORDPRESS_AUTO_UPDATE_LEVEL" "major minor none" + check_yes_no_value "WORDPRESS_ENABLE_REVERSE_PROXY" # Multisite validations check_yes_no_value "WORDPRESS_ENABLE_MULTISITE" @@ -243,6 +244,7 @@ wordpress_initialize() { if is_file_writable "$WORDPRESS_CONF_FILE"; then # Set miscellaneous configurations wordpress_conf_set "FS_METHOD" "direct" + is_boolean_yes "$WORDPRESS_ENABLE_REVERSE_PROXY" && wordpress_configure_reverse_proxy ! is_boolean_yes "$WORDPRESS_ENABLE_MULTISITE" && wordpress_configure_urls # The only variable/non-constant in the entire configuration file is '$table_prefix' replace_in_file "$WORDPRESS_CONF_FILE" "^(\s*\\\$table_prefix\s*=\s*).*" "\1'$WORDPRESS_TABLE_PREFIX';" @@ -606,6 +608,35 @@ if ( !defined( 'WP_CLI' ) ) { EOF } +######################## +# Configure reverse proxy headers +# Globals: +# * +# Arguments: +# None +# Returns: +# None +######################### +wordpress_configure_reverse_proxy() { + wordpress_conf_append "$( + cat <<"EOF" + +/** + * Handle potential reverse proxy headers. Ref: + * - https://wordpress.org/support/article/faq-installation/#how-can-i-get-wordpress-working-when-im-behind-a-reverse-proxy + * - https://wordpress.org/support/article/administration-over-ssl/#using-a-reverse-proxy + */ +if ( ! empty( $_SERVER['HTTP_X_FORWARDED_HOST'] ) ) { + $_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST']; +} + +if ( ! empty( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) \&\& 'https' === $_SERVER['HTTP_X_FORWARDED_PROTO'] ) { + $_SERVER['HTTPS'] = 'on'; +} +EOF + )" +} + ######################## # Configure application URLs for WordPress (non-Multisite) # Globals: @@ -620,6 +651,7 @@ wordpress_configure_urls() { # Note that wp-config.php is officially indented via tabs, not spaces wordpress_conf_append "$( cat <<"EOF" + /** * The WP_SITEURL and WP_HOME options are configured to access from any hostname or IP address. * If you want to access only from an specific domain, you can modify them. For example: diff --git a/bitnami/wordpress-nginx/6/debian-11/rootfs/opt/bitnami/scripts/wordpress-env.sh b/bitnami/wordpress-nginx/6/debian-11/rootfs/opt/bitnami/scripts/wordpress-env.sh index bcb3c9575b3e..9deccc1bc9d1 100644 --- a/bitnami/wordpress-nginx/6/debian-11/rootfs/opt/bitnami/scripts/wordpress-env.sh +++ b/bitnami/wordpress-nginx/6/debian-11/rootfs/opt/bitnami/scripts/wordpress-env.sh @@ -50,6 +50,7 @@ wordpress_env_vars=( WORDPRESS_FIRST_NAME WORDPRESS_LAST_NAME WORDPRESS_ENABLE_MULTISITE + WORDPRESS_ENABLE_REVERSE_PROXY WORDPRESS_MULTISITE_NETWORK_TYPE WORDPRESS_MULTISITE_EXTERNAL_HTTP_PORT_NUMBER WORDPRESS_MULTISITE_EXTERNAL_HTTPS_PORT_NUMBER @@ -135,6 +136,7 @@ export WORDPRESS_AUTH_SALT="${WORDPRESS_AUTH_SALT:-}" export WORDPRESS_SECURE_AUTH_SALT="${WORDPRESS_SECURE_AUTH_SALT:-}" export WORDPRESS_LOGGED_IN_SALT="${WORDPRESS_LOGGED_IN_SALT:-}" export WORDPRESS_NONCE_SALT="${WORDPRESS_NONCE_SALT:-}" +export WORDPRESS_ENABLE_REVERSE_PROXY="${WORDPRESS_ENABLE_REVERSE_PROXY:-no}" # only used during the first initialization # WordPress credentials export WORDPRESS_USERNAME="${WORDPRESS_USERNAME:-user}" # only used during the first initialization diff --git a/bitnami/wordpress-nginx/README.md b/bitnami/wordpress-nginx/README.md index 8718da4cc6b5..4996d91a4c6a 100644 --- a/bitnami/wordpress-nginx/README.md +++ b/bitnami/wordpress-nginx/README.md @@ -248,6 +248,7 @@ Available environment variables: - `WORDPRESS_MULTISITE_NETWORK_TYPE`: WordPress Multisite network type to enable. Valid values: `subfolder`, `subdirectory`, `subdomain`. Default: **subdomain** - `WORDPRESS_MULTISITE_ENABLE_NIP_IO_REDIRECTION`: Whether to enable IP address redirection to nip.io wildcard DNS when enabling WordPress Multisite. This is useful when running on an IP address with subdomain network type. Default: **no** - `WORDPRESS_MULTISITE_FILEUPLOAD_MAXK`: Maximum upload file size allowed for WordPress Multisite uploads, in kilobytes. Default: **81920** +- `WORDPRESS_ENABLE_REVERSE_PROXY`: Enable WordPress support for reverse proxy headers. Default: **no** ##### Database connection configuration