containers icon indicating copy to clipboard operation
containers copied to clipboard

Moodle + nginx : host issues

Open ewjoachim opened this issue 3 years ago • 5 comments

Name and Version

bitnami/moodle:4 (latest as of 2022/08/02)

What steps will reproduce the bug?

Deploying with docker compose on an ubuntu machine.

docker-compose.yml:

version: '2'
services:
  mariadb:
    restart: unless-stopped
    image: docker.io/bitnami/mariadb:10.6
    environment:
      - ALLOW_EMPTY_PASSWORD=no
      - MARIADB_USER=bn_moodle
      - MARIADB_PASSWORD=...
      - MARIADB_DATABASE=bitnami_moodle
      - MARIADB_CHARACTER_SET=utf8mb4
      - MARIADB_COLLATE=utf8mb4_unicode_ci
      - MARIADB_ROOT_PASSWORD=...
    volumes:
      - '/srv/moodle/mariadb:/bitnami/mariadb:/bitnami/mariadb'

  moodle:
    build: .
    restart: unless-stopped
    ports:
      - '127.0.0.1:8443:8443'
    environment:
      - MOODLE_PASSWORD=...
      - MOODLE_DATABASE_HOST=mariadb
      - MOODLE_DATABASE_PORT_NUMBER=3306
      - MOODLE_DATABASE_USER=bn_moodle
      - MOODLE_DATABASE_NAME=bitnami_moodle
      - MOODLE_DATABASE_PASSWORD=...
      - ALLOW_EMPTY_PASSWORD=no
      - MOODLE_EMAIL=...
      - MOODLE_SITE_NAME=...
      - MOODLE_SMTP_HOST=...
      - MOODLE_SMTP_PORT=587
      - MOODLE_SMTP_USER=...
      - MOODLE_SMTP_PASSWORD=...
      - MOODLE_SMTP_PROTOCOL=tls
      - MOODLE_HOST=moodle.my.domain.tld
      - MOODLE_REVERSEPROXY=true
      - MOODLE_SSLPROXY=true

    volumes:
      - '/srv/moodle/moodle:/bitnami/moodle'
      - '/srv/moodle/moodledata:/bitnami/moodledata'
    depends_on:
      - mariadb

Dockerfile:

FROM bitnami/moodle
RUN echo "fr_FR.UTF-8 UTF-8" >> /etc/locale.gen && locale-gen

Nginx vhost conf

server {
    listen 80;
    listen [::]:80;

    server_name moodle.my.domain.tld;
    location / {
        return 301 https://$host$request_uri;
    }
}
upstream moodle {
  server 127.0.0.1:8443;
}
server {
    listen 443 ssl;
    listen [::]:443;
    server_name moodle.my.domain.tld;

    include snippets/ssl.conf;

    location / {
        proxy_set_header Host $host;
        proxy_pass https://moodle;
    }

    ssl_certificate /etc/letsencrypt/live/domain.tld/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/domain.tld/privkey.pem; # managed by Certbot
}

Steps:

  • Visit any webpage

What is the expected behavior?

All pages load normally

What do you see instead?

Many requests to static files end as 500 errors. Loading the asset directly in the browser yields the following webpage:

Capture d’écran 2022-08-03 à 22 16 07

Additional information

Drilling in the moodle code, I see this happens when reverseproxy is true but the wwwroot is equal to the Host of the HTTP request, here: https://github.com/moodle/moodle/blob/4ce642e8ba568ca50dd71f77c0e231a5676ec8c1/lib/setuplib.php#L913-L918

That started happening when I added proxy_set_header Host $host; in the nginx configuration. If I didn't do that, I got a different problem: an infnite redirect loop that seems caused because the wwwroot was different to the Host of the HTTP request https://github.com/moodle/moodle/blob/4ce642e8ba568ca50dd71f77c0e231a5676ec8c1/lib/setuplib.php#L881

So from what I understand, either wwwroot is set to the same host as the request, and I get a bug, or it's set differently, and I get a bug.

Could you post a working nginx configuration that avoids both issues ?

ewjoachim avatar Aug 03 '22 20:08 ewjoachim

I'm exploring whether the problem might be solved by the solution outlined here: https://github.com/bitnami/bitnami-docker-moodle/pull/199#issuecomment-1036149308

If I forget to come back later with an update, feel free to ping me.

ewjoachim avatar Aug 03 '22 21:08 ewjoachim

And confirmed. Doing what was outlined there fixed the issue for me. I did it by mounting config.php as a read only volume inside the container:

    volumes:
      - '{{ moodle_dir }}/moodle:/bitnami/moodle'
      - '{{ moodle_dir }}/moodledata:/bitnami/moodledata'
      - '{{ moodle_dir }}/config.php:/bitnami/moodle/config.php:ro'

ewjoachim avatar Aug 03 '22 21:08 ewjoachim

As far as I can tell, the problem lies here: https://github.com/bitnami/containers/blob/main/bitnami/moodle/4/debian-11/rootfs/opt/bitnami/scripts/libmoodle.sh#L411-L418

In order to add additional configuration, it's written at the end of the file. We should instead locate the position of require_once lib/setuplib.php; and add our lines before that.

ewjoachim avatar Aug 03 '22 21:08 ewjoachim

Please, note that the Bitnami team is not actively monitoring GitHub Issues for this project. This issue will stay open for 20 days to allow the community to contribute, after 15 days without activity the issue will be marked as stale, being closed after 5 days.

If you would like to contribute to this container image by fixing a bug or adding a new feature, feel free to create a PR, the Bitnami team will be happy to review it and provide feedback.

rafariossaa avatar Aug 11 '22 07:08 rafariossaa

Had a similar issue, when the env var MOODLE_REVERSEPROXY is set to true static content replies with 500 status.

I'm using https://github.com/nginx-proxy/nginx-proxy as reverse proxy, what did the trick for me was just removing the MOODLE_REVERSEPROXY env var.

trennepohl avatar Aug 12 '22 14:08 trennepohl

This Issue has been automatically marked as "stale" because it has not had recent activity (for 15 days). It will be closed if no further activity occurs. Thanks for the feedback.

github-actions[bot] avatar Sep 07 '22 01:09 github-actions[bot]

Due to the lack of activity in the last 5 days since it was marked as "stale", we proceed to close this Issue. Do not hesitate to reopen it later if necessary.

github-actions[bot] avatar Sep 12 '22 01:09 github-actions[bot]

lol @ "solved" :)

ewjoachim avatar Sep 12 '22 21:09 ewjoachim