wodby / docker4drupal

Docker-based Drupal stack
https://wodby.com/docker4drupal
MIT License
1.24k stars 535 forks source link

No CSS or JS files while using HTTPS and Traefik V2 #418

Open ahernandezsouza opened 4 years ago

ahernandezsouza commented 4 years ago

Codebase Using a mounted codebase from Acquia

Describe your issue

When setting up HTTPS with Traefik v2 (similar to this post. This is for a local environment), I do get HTTPS working except for the CSS and JS files, which keep getting routed to HTTP. Anybody have a similar problem? Errors similar to this one:

GET http://project.docker.localhost/misc/drupal.js?q4jm0j net::ERR_CONNECTION_REFUSED

Contents of docker-compose.yml

version: "3"

services:
  mariadb:
    image: wodby/mariadb:$MARIADB_TAG
    container_name: "${PROJECT_NAME}_mariadb"
    stop_grace_period: 30s
    environment:
      MYSQL_ROOT_PASSWORD: $DB_ROOT_PASSWORD
      MYSQL_DATABASE: $DB_NAME
      MYSQL_USER: $DB_USER
      MYSQL_PASSWORD: $DB_PASSWORD
    volumes:
      - ./mariadb-init:/docker-entrypoint-initdb.d # Place init .sql file(s) here.
      - .databases:/var/lib/mysql # Use bind mount

  php:
    image: wodby/drupal-php:$PHP_TAG
    container_name: "${PROJECT_NAME}_php"
    environment:
      PHP_SENDMAIL_PATH: /usr/sbin/sendmail -t -i -S mailhog:1025
#      PHP_SENDMAIL_PATH: /usr/sbin/sendmail -t -i -S opensmtpd:25
      DB_HOST: $DB_HOST
      DB_PORT: $DB_PORT
      DB_USER: $DB_USER
      DB_PASSWORD: $DB_PASSWORD
      DB_NAME: $DB_NAME
      DB_DRIVER: $DB_DRIVER
      PHP_FPM_USER: wodby
      PHP_FPM_GROUP: wodby
      COLUMNS: 80 # Set 80 columns for docker exec -it.
## Read instructions at https://wodby.com/docs/stacks/php/local/#xdebug
#      PHP_XDEBUG: 1
#      PHP_XDEBUG_DEFAULT_ENABLE: 1
#      PHP_XDEBUG_REMOTE_CONNECT_BACK: 0
#      PHP_IDE_CONFIG: serverName=my-ide
#      PHP_XDEBUG_IDEKEY: "my-ide"
#      PHP_XDEBUG_REMOTE_HOST: host.docker.internal # Docker 18.03+ Mac/Win
#      PHP_XDEBUG_REMOTE_HOST: 172.17.0.1 # Linux
#      PHP_XDEBUG_REMOTE_HOST: 10.254.254.254 # macOS, Docker < 18.03
#      PHP_XDEBUG_REMOTE_HOST: 10.0.75.1 # Windows, Docker < 18.03
#      PHP_XDEBUG_REMOTE_LOG: /tmp/php-xdebug.log
## PHPUnit Drupal testing configurations
#      SIMPLETEST_BASE_URL: "http://nginx"
#      SIMPLETEST_DB: "${DB_DRIVER}://${DB_USER}:${DB_PASSWORD}@${DB_HOST}/${DB_NAME}#tests_"
#      MINK_DRIVER_ARGS_WEBDRIVER: '["chrome", {"browserName":"chrome","goog:chromeOptions":{"args":["--disable-gpu","--headless"]}}, "http://chrome:9515"]'

    volumes:
      - ./:/var/www/html
## For macOS users (https://wodby.com/docs/stacks/drupal/local#docker-for-mac)
#      - ./:/var/www/html:cached # User-guided caching
#      - docker-sync:/var/www/html # Docker-sync
## For XHProf and Xdebug profiler traces
#      - files:/mnt/files

  apache:
    image: wodby/apache:$APACHE_TAG
    container_name: "${PROJECT_NAME}_apache"
    depends_on:
      - php
    environment:
      APACHE_LOG_LEVEL: debug
      APACHE_BACKEND_HOST: php
      APACHE_VHOST_PRESET: php
      APACHE_DOCUMENT_ROOT: /var/www/html/docroot
    volumes:
      - ./:/var/www/html
## For macOS users (https://wodby.com/docs/stacks/drupal/local#docker-for-mac)
##      - ./:/var/www/html:cached # User-guided caching
##      - docker-sync:/var/www/html # Docker-sync
    labels:
      - "traefik.http.routers.${PROJECT_NAME}_apache.entrypoints=web"
      - "traefik.http.routers.${PROJECT_NAME}_apache.rule=Host(`${PROJECT_BASE_URL}`)"
      - "traefik.http.middlewares.${PROJECT_NAME}_apache-https-redirect.redirectscheme.scheme=https"
      - "traefik.http.routers.${PROJECT_NAME}_apache.middlewares=${PROJECT_NAME}_apache-https-redirect"
      - "traefik.http.routers.${PROJECT_NAME}_https_apache.rule=Host(`${PROJECT_BASE_URL}`)"
      - "traefik.http.routers.${PROJECT_NAME}_https_apache.tls=true"
      - "traefik.http.routers.${PROJECT_NAME}_https_apache.entrypoints=websecure"

  pma:
    image: phpmyadmin/phpmyadmin
    container_name: "${PROJECT_NAME}_pma"
    environment:
      PMA_HOST: $DB_HOST
      PMA_USER: $DB_USER
      PMA_PASSWORD: $DB_PASSWORD
      PHP_UPLOAD_MAX_FILESIZE: 1G
      PHP_MAX_INPUT_VARS: 1G
    labels:
      - "traefik.http.routers.${PROJECT_NAME}_pma.rule=Host(`pma.${PROJECT_BASE_URL}`)"

  portainer:
    image: portainer/portainer
    container_name: "${PROJECT_NAME}_portainer"
    command: --no-auth -H unix:///var/run/docker.sock
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    labels:
      - "traefik.http.routers.${PROJECT_NAME}_portainer.rule=Host(`portainer.${PROJECT_BASE_URL}`)"

  traefik:
    image: traefik:v2.0
    container_name: "${PROJECT_NAME}_traefik"
    command:
      - --api.insecure=true
      - --providers.docker=true
      - --log.level=DEBUG
      - --entrypoints.web.address=:80
      - --entrypoints.websecure.address=:443
      - --configFile=traefik.toml
    ports:
      - '443:443'
      - '8000:80'
      - '8080:8080' # Dashboard
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

    labels:
      - "traefik.http.routers.redirs.rule=Host(`${PROJECT_BASE_URL}`)"
      - "traefik.http.routers.redirs.entrypoints=web"
      - "traefik.http.routers.redirs.entrypoints=websecure"
      - "traefik.http.routers.redirs.middlewares=redirect-to-https"
      - "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"

Contents of your .env

### PROJECT SETTINGS

PROJECT_NAME=project_name
PROJECT_BASE_URL=project.docker.localhost

DB_NAME=drupal
DB_USER=drupal
DB_PASSWORD=drupal
DB_ROOT_PASSWORD=password
DB_HOST=mariadb
DB_PORT=3306
DB_DRIVER=mysql

### --- MARIADB ----

MARIADB_TAG=10.4-3.6.8
#MARIADB_TAG=10.3-3.6.8
#MARIADB_TAG=10.2-3.6.8
#MARIADB_TAG=10.1-3.6.8

### --- VANILLA DRUPAL ----

#DRUPAL_TAG=8-4.16.3
DRUPAL_TAG=7-4.16.3

### --- PHP ----

# Linux (uid 1000 gid 1000)

#PHP_TAG=7.3-dev-4.14.2
PHP_TAG=7.2-dev-4.14.2
#PHP_TAG=7.1-dev-4.14.2
#PHP_TAG=5.6-dev-4.14.2

# macOS (uid 501 gid 20)

#PHP_TAG=7.3-dev-macos-4.14.2
#PHP_TAG=7.2-dev-macos-4.14.2
#PHP_TAG=7.1-dev-macos-4.14.2
#PHP_TAG=5.6-dev-macos-4.14.2

### --- NGINX ----

#NGINX_TAG=1.17-5.7.4
#NGINX_TAG=1.16-5.7.4

#NGINX_VHOST_PRESET=drupal8
#NGINX_VHOST_PRESET=drupal7
#NGINX_VHOST_PRESET=drupal6

### --- SOLR ---

SOLR_CONFIG_SET="search_api_solr_8.x-3.2"
#SOLR_CONFIG_SET="search_api_solr_8.x-2.7"
#SOLR_CONFIG_SET="search_api_solr_8.x-1.2"
#SOLR_CONFIG_SET="search_api_solr_7.x-1.14"

SOLR_TAG=8-4.1.2
#SOLR_TAG=7-4.1.2
#SOLR_TAG=6-4.1.2
#SOLR_TAG=5-4.1.2

### --- ELASTICSEARCH ---

ELASTICSEARCH_TAG=7-5.3.0
#ELASTICSEARCH_TAG=6-5.3.0

### --- KIBANA ---

KIBANA_TAG=7-5.3.0
#KIBANA_TAG=6-5.3.0

### --- REDIS ---

REDIS_TAG=4-3.1.4
#REDIS_TAG=5-3.1.4

### --- NODE ---

NODE_TAG=12-0.29.0
#NODE_TAG=10-0.29.0
#NODE_TAG=8-0.29.0

### --- VARNISH ---

VARNISH_TAG=6.0-4.3.6
#VARNISH_TAG=4.1-4.3.6

### --- POSTGRESQL ----

POSTGRES_TAG=12-1.8.0
#POSTGRES_TAG=11-1.8.0
#POSTGRES_TAG=10-1.8.0
#POSTGRES_TAG=9.6-1.8.0
#POSTGRES_TAG=9.5-1.8.0
#POSTGRES_TAG=9.4-1.8.0

### OTHERS

ADMINER_TAG=4-3.8.1
APACHE_TAG=2.4-4.1.5
ATHENAPDF_TAG=2.10.0
DRUPAL_NODE_TAG=1.0-2.0.0
MEMCACHED_TAG=1-2.3.6
OPENSMTPD_TAG=6.0-1.5.4
RSYSLOG_TAG=latest
SELENIUM_CHROME_TAG=3.141
WEBGRIND_TAG=1-1.13.1
XHPROF_TAG=2.0.0
iVegas commented 4 years ago

You have 8000 port defined instead of 80, so fallback from https to http wouldn't work as expected.

Why is it still routed to http? That depends on the proper traefik https configuration. Usually, that caused by the incorrect TLS configuration (errors during TLS handshake) or misconfiguration of SSL certificates (or Let's Encrypt).