1

I tried to make moode run behind a ssl reverse proxy using this solution but I get the following error:

Reverse proxy enabled, server can not be accessed directly, sorry. Please contact server administrator.

In the moodle's configuration I enabled the following settings:

$CFG->reverseproxy = true;
$CFG->sslproxy = true;

Thus resulting to this configuration.

For reverse proxy I use nginx that has the following settings:

events {
  worker_connections  768;
}

http {
  include  /etc/nginx/mime.types;
  default_type  application/octet-stream;

  charset  utf-8;

  gzip  on;
  gzip_disable  "msie6";
  client_max_body_size 10000M;

  # Mysql apache-based variant
  server {
    listen  6440 ssl;
    server_name  0.0.0.0;

    ssl_certificate     /etc/nginx/certs/cert.pem;
    ssl_certificate_key /etc/nginx/certs/key.pem;
    ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers         HIGH:!aNULL:!MD5;

    location / {
              proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            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;
          # In case or running another port please replace the value bellow.
            proxy_pass http://^ip^;
      }
  }
}

Where ^ip^ is the ip I reverse proxy the requests. Also for the setup url I use in my case that I run the WHOLE setup in a docker containers the following https://0.0.0.0:6440 that is NOT the serving ip.

Also the docker-compose is the following:

version: '2'
services:
  nginx_reverse:
    image: nginx:alpine
    ports:
      - "6440:6440"
    links:
      - 'moodle_mysql_reverse'
    restart: always
    volumes:
      - './conf/nginx/nginx_ssl_reverse.conf:/etc/nginx/nginx.conf:ro'
      - './conf/certs:/etc/nginx/certs:ro'

  moodle_mysql_db_reverse:
    image: mysql
    environment:
      MYSQL_RANDOM_ROOT_PASSWORD: "yes"
      MYSQL_ONETIME_PASSWORD: "yes"
      MYSQL_DATABASE: "${MOODLE_DB_NAME}"
      MYSQL_USER: '${MOODLE_MYSQL_USER}'
      MYSQL_PASSWORD: '${MOODLE_MYSQL_PASSWORD}'

  moodle_mysql_reverse:
    image: ellakcy/moodle:mysql_maria_apache
    links:
      - "moodle_mysql_db_reverse:moodle_db"
    environment:
      MOODLE_DB_HOST: "moodle_db"
      MOODLE_DB_NAME: "${MOODLE_DB_NAME}"
      MOODLE_DB_USER: '${MOODLE_MYSQL_USER}'
      MOODLE_DB_PASSWORD: "${MOODLE_MYSQL_PASSWORD}"
      MOODLE_ADMIN: "${MOODLE_ADMIN}"
      MOODLE_ADMIN_PASSWORD: "${MOODLE_ADMIN_PASSWORD}"
      MOODLE_URL: "https://0.0.0.0:6440"
      MOODLE_REVERSE_LB: "true"
      MOODLE_SSL: "true"

Do you known why I get the error and how to fix that?

Dimitrios Desyllas
  • 523
  • 2
  • 10
  • 27

1 Answers1

0

Regardless if it is a docker-based solution or not is recomended the proxy pass NOT to provide the Host http header. Therefore the nginx reverse proxy configuration should be the one:

events {
  worker_connections  768;
}

http {
  include  /etc/nginx/mime.types;
  default_type  application/octet-stream;

  charset  utf-8;

  gzip  on;
  gzip_disable  "msie6";
  client_max_body_size 10000M;

  # Mysql apache-based variant
  server {
    listen  6440 ssl;
    server_name  0.0.0.0;

    ssl_certificate     /etc/nginx/certs/cert.pem;
    ssl_certificate_key /etc/nginx/certs/key.pem;
    ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers         HIGH:!aNULL:!MD5;

    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;
          # In case or running another port please replace the value bellow.
            proxy_pass http://^ip^;
      }
  }
}

As you can see the following line should be missing and not exist in your reverse proxy nginx configuration:

        proxy_set_header Host $host;
Dimitrios Desyllas
  • 523
  • 2
  • 10
  • 27