Installing behind a nginx proxy gives - Error code: nopermissions

Installing behind a nginx proxy gives - Error code: nopermissions

by Pierre V -
Number of replies: 6

Hello the moodle community,

For a university project I must deploy a static website and a moodle instance (i have acces to one server: Ubuntu 16.04, php7.0, mysql5.7).

For this purpose i have stored the static website on the VPS host and I use a docker container for the moodle instance.

To make those two thing public, I use a nginx proxy with the following config in the server block:

server {  
  
    listen 80;  
  
    listen [::]:80;  
  
    server_name 104.238.164.33;  
  
    set $base /var/www/public/;  
  
    root $base;  
  
# $uri, index.html  
  
  location / {  
  
    try_files $uri $uri/ /index.html;  
  
  }  
  
  location /moodle/ {  
  
    proxy_pass http://172.20.0.3/;  
  
    proxy_redirect off;  
  
    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-Host $server_name;  
  
  }  
  
}  

the / location only hold static html.

the /moodle/ location point to the ip of the container, I build using this config:

https://github.com/jda/docker-moodle

To make it work i made the following change:

to make the moodle instace work behind the proxy, i just add in the config.php file line :

$CFG->reverseproxy=1;

Then I modify the docker-compose.yml to remove the exposed port

version: '3'  
  
services:  
dbapp:  
    image: mysql:5
    restart: always  
    volumes:  
        - db-volume:/var/lib/mysql  
    env_file:  
        - moodle_variables.env  
    networks:  
        - backendDB  

moodleapp:  
    build:  
        context: .  
    links:  
        - dbapp:DB  
    depends_on:  
        - dbapp  
    restart: always  
    volumes:  
        - moodleapp-data:/var/moodledata  
    env_file:  
        - moodle_variables.env  
    networks:  
       - backendDB  
       - frontendWEB  

  
volumes:  
    db-volume:  
    moodleapp-data:  
  
networks:  
    backendDB:  
    frontendWEB:

Then to make it use the last moodle version i change the git command in the Dockerfile

git clone -b MOODLE_34_STABLE git://git.moodle.org/moodle.git --depth=1 && \

Once all this is done you can build the image and deploy with:

docker-compose build  
docker-compose up -d

Once deployed i access the server with the following URL: http://104.238.164.33/moodle/

I can validate the license and all the plugins are installed, but once the installation script begin i get the error as showned in the attached screenshot.

When i check on the sql container all the table are created. What could make the server believe it cant access it ?
I am using this technique (proxy+docker) as it was the easiest path for me.
Seems like its an issue on the php side how could i debug this ?

Thank you for reading all this!


Attachment Screenshot from 2018-05-07 13-41-31.png
Average of ratings: -
In reply to Pierre V

Re: Installing behind a nginx proxy gives - Error code: nopermissions

by Matteo Scaramuccia -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Hello,
never tried that docker env - it seems no more maintained - but it looks like Moodle tries to perform permissions checking even during the installation which is normally disabled 'till the installation will finish.

Did you try the same docker env without using the rev proxy e.g. in a testing env just to be sure that your issue is actually due to the rev proxy?
At first glance, the nginx proxy settings look correct.

HTH,
Matteo

In reply to Matteo Scaramuccia

Re: Installing behind a nginx proxy gives - Error code: nopermissions

by Pierre V -

Hi Matteo!

Thanks for helping me.

Even if the repo isnt maintained, the Dockerfile follow the moodle installation with apache pulling directly from sources. So after all the build is fresh.

As you mentioned, I just tried to install this container config without a proxy.

That is to say that the content is directly served by the apache of the moodle container. It all work great without issue.

I think the culprit might be the $CFG->reverseproxy=1 because its the only change between this config and the first one.

In reply to Pierre V

Re: Installing behind a nginx proxy gives - Error code: nopermissions

by Matteo Scaramuccia -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Hi Pierre,
well, you could have hit a bug in the installation stage when done behind a rev proxy.
I'd give it a try, spare time permitted, to look if worth filing an issue into the Moodle Tracker, if replicable.

Why not installing Moodle without the proxy configuration and then change the configuration to be served via the proxy?
It would be a matter of changing the wwwroot configuration and adding rev proxy setting, after a successful installation.

HTH,
Matteo

In reply to Matteo Scaramuccia

Re: Installing behind a nginx proxy gives - Error code: nopermissions

by Pierre V -

I was thinking of letting the virtualisation down to install it the old school way. Thing is why wouldnt i get i the same issue thoughtful


In reply to Matteo Scaramuccia

Re: Installing behind a nginx proxy gives - Error code: nopermissions

by Pierre V -

I fixed my issue by installing moodle without the proxy and then turning it on.

The installation went well but now i have one issue where the javascript cant load.

To see it in action goes there: https://tandem.ulaval.ca/moodle/

i get a 404 error on all javascript asset. where should i look to fix my issue ?


EDIT: I fixed my issue by removing the gzip part of my nginx config. 

Removed use this line in the nginx conf :  gzip_types text/plain text/css text/xml application/json application/javascript application/xml+rss application/atom+xml image/svg+xml;

In reply to Pierre V

Re: Installing behind a nginx proxy gives - Error code: nopermissions

by Kevin Collins -

I can confirm that I'm having this issue with a Træfik Reverse Proxy config too with the latest Moodle 3.4+ release (as of 2018-05-11).  I tried postgres and mysql with the same results, so it doesn't appear to be database-related (a guess)..  Any solution that you could find?