Docker WordPress Subdirectory – ERR_TOO_MANY_REDIRECTS


I’m creating a wordpress blog based on docker container with official image. When I use no directories, the wordspress works fine but when I use "/blog" directory using WP_HOME and WP_SITEURL it’s give me ERR_TOO_MANY_REDIRECTS on /blog/wp-admin/install.php (302).

How can I achieve docker wordpress with directories?

Docker Image

docker pull wordpress:latest


FROM wordpress:latest

COPY config/ /var/www/html/

RUN a2enmod 

config folder has custom wp-config.php with WP_HOME and WP_SITEURL


     * The base configuration for WordPress
     * The wp-config.php creation script uses this file during the
     * installation. You don't have to use the web site, you can
     * copy this file to "wp-config.php" and fill in the values.
     * This file contains the following configurations:
     * * MySQL settings
     * * Secret keys
     * * Database table prefix
     * * ABSPATH
     * @link
     * @package WordPress
    define( 'WP_HOME', 'http://localhost/blog' ); 
    define( 'WP_SITEURL', 'http://localhost/blog' );
    // ** MySQL settings - You can get this info from your web host ** //
    /** The name of the database for WordPress */
    define( 'DB_NAME', 'database_name_here' );
    /** MySQL database username */
    define( 'DB_USER', 'username_here' );
    /** MySQL database password */
    define( 'DB_PASSWORD', 'password_here' );
    /** MySQL hostname */
    define( 'DB_HOST', 'localhost' );
    /** Database Charset to use in creating database tables. */
    define( 'DB_CHARSET', 'utf8' );
    /** The Database Collate type. Don't change this if in doubt. */
    define( 'DB_COLLATE', '' );
     * Authentication Unique Keys and Salts.
     * Change these to different unique phrases!
     * You can generate these using the {@link secret-key service}
     * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
     * @since 2.6.0
    define( 'AUTH_KEY',         'put your unique phrase here' );
    define( 'SECURE_AUTH_KEY',  'put your unique phrase here' );
    define( 'LOGGED_IN_KEY',    'put your unique phrase here' );
    define( 'NONCE_KEY',        'put your unique phrase here' );
    define( 'AUTH_SALT',        'put your unique phrase here' );
    define( 'SECURE_AUTH_SALT', 'put your unique phrase here' );
    define( 'LOGGED_IN_SALT',   'put your unique phrase here' );
    define( 'NONCE_SALT',       'put your unique phrase here' );

 WordPress Database Table prefix.
 * You can have multiple installations in one database if you give each
 * a unique prefix. Only numbers, letters, and underscores please!
$table_prefix = 'wp_';

 * For developers: WordPress debugging mode.
 * Change this to true to enable the display of notices during development.
 * It is strongly recommended that plugin and theme developers use WP_DEBUG
 * in their development environments.
 * For information on other constants that can be used for debugging,
 * visit the documentation.
 * @link
define( 'WP_DEBUG', false );

/* That's all, stop editing! Happy publishing. */

/** Absolute path to the WordPress directory. */
if ( ! defined( 'ABSPATH' ) ) {
        define( 'ABSPATH', __DIR__ . '/' );

// define('FORCE_SSL_ADMIN', true);
if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false)

/** Sets up WordPress vars and included files. */
require_once ABSPATH . 'wp-settings.php';

Source: Docker Questions

Categorised as apache, docker, php, wordpress Tagged , , ,


Leave a Reply

Still Have Questions?

Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us