Dockerized drupal 在本地渲染良好,但在 Apache 中通过代理传递时则不然

问题描述 投票:0回答:1

我使用以下内容成功对现有的 drupal 7 网站进行了 docker 化:

# 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:

在本地访问时,即通过转到

http://localhost:8006
,这可以按预期工作。然后我想使用以下 apache2 设置将其部署在服务器上:

# mysite.conf
<VirtualHost *:443>
    ServerName  mysite.com
    ServerAdmin [email protected]
    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>

当我这样做时,只有基本的 HTML 通过,没有 js/css,并且到非图像文件/* 的链接也不起作用(得到 404)。服务器端的日志中没有任何内容。如果有人有任何想法可以指出我正确的方向,我将非常感激!

docker drupal apache2
1个回答
0
投票

我找到了缺失的细节,我将其发布在这里希望对其他人有所帮助:在

sites/default/settings.php
中,需要设置显式网址:

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

之后,一切都通过反向代理进行。

© www.soinside.com 2019 - 2024. All rights reserved.