dockerdrupalapache2

Dockerized drupal renders fine locally but not when proxy-passed in Apache


I successfully dockerized an existing drupal 7 website with the following:

# Dockerfile
FROM drupal:7.101-php8.2-apache
COPY webroot /var/www/html
WORKDIR /var/www/html
EXPOSE 8006
# docker-compose.yaml
services:
  mysql:
    image: mysql:5.7
    command: --max_allowed_packet=32505856
    container_name: dbname
    restart: always
    volumes:
      - ./dbname.sql:/docker-entrypoint-initdb.d/dbimport.sql
      - ./dbdata:/var/lib/mysql
      - /tmp/dbname/mysqld:/var/run/mysqld
    environment:
      MYSQL_ROOT_PASSWORD: some_password
      MYSQL_DATABASE: dbname
      MYSQL_USER: webadmin
      MYSQL_PASSWORD: some_password
    healthcheck:
      test: ["CMD", "mysqladmin", "-u", "webadmin", "-psome_password", "ping", "-h", "localhost"]
      timeout: 10s
      retries: 10
    ports:
      - "3304:3306"

  drupal:
    container_name: my_drupal
    build:
      context: ./
      dockerfile: Dockerfile
    depends_on:
      mysql:
        condition: service_healthy
    volumes:
      - ./files:/var/www/html/files
      - /tmp/dbname/mysqld:/var/run/mysqld
    working_dir: /var/www/html
    restart: always
    ports:
      - "8006:80"

volumes:
  dbdata:

This works as expected when accessed locally, i.e. by going to http://localhost:8006. Then I wanted to deploy it on the server using the following apache2 setup:

# mysite.conf
<VirtualHost *:443>
    ServerName  mysite.com
    ServerAdmin me@mysite.com
    Protocols h2 http/1.1

    SSLEngine on
    SSLCertificateFile "/etc/ssl/certs/mycert.crt"
    SSLCertificateKeyFile "/etc/ssl/private/mycert.key"
    SSLCertificateChainFile "/etc/ssl/certs/mycert.chain.crt"

    <Directory "/">
        Order allow,deny
        Allow from all
        Require all granted
    </Directory>

    ProxyPreserveHost on
    ProxyPass / http://localhost:8006/
    ProxyPassReverse / http://localhost:8006/

    ErrorLog /var/log/apache2/mysite.errors.log
</VirtualHost>

When I do this, only the basic HTML comes through, no js/css and the links to non-image files/* do not work either (getting 404). Nothing in the logs on the server side. If anyone has any ideas to point me in the right direction, I'd be very grateful!


Solution

  • I figured out the missing detail, and I am posting it here in hope that it helps someone else: in sites/default/settings.php, the explicit url needs to be set:

    $base_url = 'https://example.com';
    

    After that, everything works through the reverse proxy.