• Hello everyone, I’m currently in the process of setting up WordPress using Docker Compose and Apache which is running on the host as a reverse proxy (unfortunately, I can’t use nginx). Additionally, I use Cloudflare. When I attempt to access the site using the domain, I encounter an immediate redirect to “https://127.0.0.1:8585/wp-admin/install.php” instead of the desired “https://example.com/wp-admin/install.php”.

    To address this, I modified the configuration by adding the following two lines:

    define('WP_HOME','https://example.com');
    define('WP_SITEURL','https://example.com');

    This adjustment effectively resolves the problem. However, upon completing the WordPress installation process, a new issue arises where the front page consistently redirects to the local IP address 127.0.0.1 even though i have used the domain to access the site. By the way, I have PHPMyAdmin also running within the same container, and the reverse proxy is functioning flawlessly. Therefore, I suspect the issue might be related to the WordPress Docker image. Is there anyone who has a solution for this problem?

    docker compose config:

    version: '3'
    
    services:
      wp:
        image: wordpress:latest # https://hub.docker.com/_/wordpress/
        ports:
          - 127.0.0.1:8585:80 # change ip if required
        volumes:
          - ./config/php.conf.ini:/usr/local/etc/php/conf.d/conf.ini
          - ./wp-app:/var/www/html # Full wordpress project
          #- ./plugin-name/trunk/:/var/www/html/wp-content/plugins/plugin-name # Plugin development
          #- ./theme-name/trunk/:/var/www/html/wp-content/themes/theme-name # Theme development
        environment:
          WORDPRESS_DB_HOST: db
          WORDPRESS_DB_NAME: "${DB_NAME}"
          WORDPRESS_DB_USER: "${DB_USER}"
          WORDPRESS_DB_PASSWORD: "${DB_PASSWORD}"
          WORDPRESS_CONFIG_EXTRA: |
                   define('WP_HOME','https://example.com');
                   define('WP_SITEURL','https://example.com');
        depends_on:
          - db
        links:
          - db
    
      wpcli:
        image: wordpress:cli
        volumes:
          - ./config/php.conf.ini:/usr/local/etc/php/conf.d/conf.ini
          - ./wp-app:/var/www/html
        environment:
          WORDPRESS_DB_HOST: db
          WORDPRESS_DB_NAME: "${DB_NAME}"
          WORDPRESS_DB_USER: "${DB_USER}"
          WORDPRESS_DB_PASSWORD: "${DB_PASSWORD}"
        depends_on:
          - db
          - wp
    ##################################################################################
    ##################################################################################
    ##################################################################################
      pma:
        image: phpmyadmin/phpmyadmin
        environment:
          # https://docs.phpmyadmin.net/en/latest/setup.html#docker-environment-variables
          PMA_HOST: db
          PMA_PORT: 3306
          MYSQL_ROOT_PASSWORD: "${DB_ROOT_PASSWORD}"
          UPLOAD_LIMIT: 100M
        ports:
          - 127.0.0.1:8686:80
        links:
          - db:db
    ##################################################################################
    ##################################################################################
    ##################################################################################
      db:
        image: mariadb:latest # https://hub.docker.com/_/mysql/ - or mariadb https://hub.docker.com/_/mariadb
        ports:
          - 127.0.0.1:5460:3306 # change ip if required
        command: [
            '--default_authentication_plugin=mysql_native_password',
            '--character-set-server=utf8mb4',
            '--collation-server=utf8mb4_unicode_ci'
        ]
        volumes:
          - ./wp-data:/docker-entrypoint-initdb.d
          - db_data:/var/lib/mysql
        environment:
          MYSQL_ROOT_PASSWORD: "${DB_ROOT_PASSWORD}"
    
    volumes:
      db_data:

    apache config:

    <VirtualHost *:443>
        ServerName example.com
        ServerAlias www.example.com
        RemoteIPHeader CF-Connecting-IP
    
        SSLEngine On
        SSLCertificateFile /etc/apache2/ssl/example.com/example.com.pem
        SSLCertificateKeyFile /etc/apache2/ssl/example.com/example.com.key
    
        ProxyPass / https://127.0.0.1:8585/
        ProxyPassReverse / https://127.0.0.1:8585/
    
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>
Viewing 1 replies (of 1 total)
  • Here are some ideas off the top of my head that might help:

    1. trusted proxies: In some cases, you might need to inform WordPress about which proxies are trusted. This can be done within the wp-config.php.
    2. review the .htaccess file of WordPress to see if there are any redirect rules that might be causing the incorrect redirection.
    3. using PHPMyAdmin or another tool, verify that the siteurl and home options in the wp_options table are correctly set to your domain.
    4. consider checking the error logs of both Apache and WordPress. There might be more error messages that can assist you in diagnosing the problem.
Viewing 1 replies (of 1 total)
  • The topic ‘WordPress Site with Docker behind Apache reverse proxy keeps redirecting from do’ is closed to new replies.