I think this is becoming an eternal problem which may need a good solution, as Docker is being more and more popular.
My problem comes when trying to reverse Proxy to a Docker container which exposes a port (8080) with a bitnami/moodle image. I've tried for days all the possible solutions on the internet and nothing helps...
The better approaches are close to the solution, but I still get the page without static files or a message telling
'reverse proxy enabled so the server cannot be accessed directly. please contact the server administrator.'
I've tried both NGINX and Apache2, as I don't mind which one to use. Here are both configurations and also the config.php
for the Moodle instance in the container.
Apache2
<VirtualHost *:80> ServerName my.domain.com ProxyRequests Off ProxyPreserveHost On ProxyPass / http://127.0.0.1:8080/ ProxyPassReverse / http://127.0.0.1:8080/ </VirtualHost>
NGINX
server { listen 443; server_name my.domain.com; access_log /var/log/nginx/domain.com_access.log; error_log /var/log/nginx/domain.com_error.log; location / { proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_cache_bypass $http_upgrade; proxy_pass_request_headers on; proxy_pass http://127.0.0.1:8080; } }
config.php (Moodle)
<?php // Moodle configuration file
unset($CFG);
global $CFG;
$CFG = new stdClass();
$CFG->dbtype = 'mariadb';
$CFG->dblibrary = 'native';
$CFG->dbhost = 'mariadb';
$CFG->dbname = 'moodle';
$CFG->dbuser = 'root';
$CFG->dbpass = 'moodle';
$CFG->prefix = 'mdl_';
$CFG->dboptions = array (
'dbpersist' => 0,
'dbport' => 3306,
'dbsocket' => '',
'dbcollation' => 'utf8mb4_general_ci',
);
if (empty($_SERVER['HTTP_HOST'])) {
$_SERVER['HTTP_HOST'] = 'my.domain.com';
}
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
$CFG->wwwroot = 'https://' . $_SERVER['HTTP_HOST'];
} else {
$CFG->wwwroot = 'http://' . $_SERVER['HTTP_HOST'];
}
$CFG->dataroot = '/bitnami/moodledata';
$CFG->admin = 'admin';
$CFG->reverseproxy = true;
$CFG->directorypermissions = 02775;
require_once(__DIR__ . '/lib/setup.php');
// There is no php closing tag in this file,
// it is intentional because it prevents trailing whitespace problems!
Any idea? I think i've followed all the hints out there right...