title: Using moodle 3.3.2 over custom docker image with fpm: endless 303 redirect loop
body: <p>I am trying to create an alpine-fpm based package for <a href="https://github.com/ellakcy/docker-moodle/tree/dev" rel="nofollow noreferrer">this</a> project But I cannot make the alpine_mysql based image to run via an nginx no matter how hard I tried. The problem I get is that the mooodle installation does a redirect loop therefore the browser does not serve the moodle.</p>
  
  <p>The nginx configuration is in <a href="https://github.com/ellakcy/docker-moodle/blob/dev/conf/nginx/nginx.conf" rel="nofollow noreferrer">this</a> file whilst I tried also this option without success (not commited changes yet):</p>
  
  
  
  <pre><code>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;
  
        server {
          listen  80 default_server;
          server_name  _;
  
          root  /var/www/html;
          index  index.php;
  
          location / {
            try_files  $uri $uri/ =404;
          }
  
          location ~ \.php$ {
            fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
            fastcgi_param  SERVER_SOFTWARE    nginx;
            fastcgi_param  QUERY_STRING       $query_string;
            fastcgi_param  REQUEST_METHOD     $request_method;
            fastcgi_param  CONTENT_TYPE       $content_type;
            fastcgi_param  CONTENT_LENGTH     $content_length;
            fastcgi_param  DOCUMENT_ROOT      $document_root;
            fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
            fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
            fastcgi_param  REQUEST_URI        $request_uri;
            fastcgi_param  DOCUMENT_URI       $document_uri;
            fastcgi_param  SERVER_PROTOCOL    $server_protocol;
            fastcgi_param  REMOTE_ADDR        $remote_addr;
            fastcgi_param  REMOTE_PORT        $remote_port;
            fastcgi_param  SERVER_ADDR        $server_addr;
            fastcgi_param  SERVER_PORT        $server_port;
            fastcgi_param  SERVER_NAME        $server_name;
            fastcgi_param PATH_INFO $fastcgi_path_info;
            fastcgi_read_timeout 600;
  
            fastcgi_intercept_errors  on;
            fastcgi_pass  moodle_mysql_alpine:9000;
          }
        }
      }
  </code></pre>
  
  <p>Also my docker-compose is <a href="https://github.com/ellakcy/docker-moodle/blob/dev/docker-compose.yml" rel="nofollow noreferrer">this</a> file, on it you can focus on these lines:</p>
  
  <pre class="lang-yml prettyprint-override"><code>  #Basic alpine fpm image
    alpine_fpm_base:
      build:
        context: .
        dockerfile: dockerfiles/fpm_alpine/Dockerfile_base
      image: ellakcy/moodle:alpine_fpm_base
  
    moodle_mysql_alpine_db:
      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}'
  
    # Mysql Enabled image
  
    nginx:
     image: nginx:alpine
     ports:
       - "7070:80"
     volumes:
       - './conf/nginx/nginx.conf:/etc/nginx/nginx.conf:ro'
     links:
       - 'moodle_mysql_alpine'
     volumes_from:
       - 'moodle_mysql_alpine'
  
    moodle_mysql_alpine:
      build:
        context: .
        dockerfile: dockerfiles/fpm_alpine/Dockerfile_mysql
      image: ellakcy/moodle:mysql_maria_fpm_alpine
      links:
        - "moodle_mysql_alpine_db:moodle_db"
        - "alpine_fpm_base"
      environment:
        MOODLE_DB_HOST: "moodle_mysql_alpine_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: "http://0.0.0.0:7070"
  </code></pre>
  
  <p>I try to run it via <code>docker-compose rm &amp;&amp; docker-compose up moodle_mysql_alpine_db moodle_mysql_alpine nginx</code> command. Also further investigation of the issue on the nginx's logs shows that for some reason the nginx throws 303 redirect:</p>
  
  <pre><code>172.25.0.1 - - [30/Sep/2017:21:02:57 +0000] "GET / HTTP/1.1" 303 429 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"
  172.25.0.1 - - [30/Sep/2017:21:02:57 +0000] "GET / HTTP/1.1" 303 429 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"
  172.25.0.1 - - [30/Sep/2017:21:02:57 +0000] "GET / HTTP/1.1" 303 429 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"
  172.25.0.1 - - [30/Sep/2017:21:02:57 +0000] "GET / HTTP/1.1" 303 429 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"
  172.25.0.1 - - [30/Sep/2017:21:02:57 +0000] "GET / HTTP/1.1" 303 429 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"
  172.25.0.1 - - [30/Sep/2017:21:02:57 +0000] "GET / HTTP/1.1" 303 429 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"
  172.25.0.1 - - [30/Sep/2017:21:02:57 +0000] "GET / HTTP/1.1" 303 429 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"
  172.25.0.1 - - [30/Sep/2017:21:02:57 +0000] "GET / HTTP/1.1" 303 429 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"
  172.25.0.1 - - [30/Sep/2017:21:02:58 +0000] "GET / HTTP/1.1" 303 429 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"
  172.25.0.1 - - [30/Sep/2017:21:02:58 +0000] "GET / HTTP/1.1" 303 429 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"
  </code></pre>
  
  <p>Do you fellows have any idea why that happens?</p>
  
  <h1>Edit 1:</h1>
  
  <p>I tried to follow an nginx configuration based on <a href="https://moopi.uk/mod/page/view.php?id=78" rel="nofollow noreferrer">https://moopi.uk/mod/page/view.php?id=78</a> resulting to this:</p>
  
  <pre><code>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;
  
    server {
      listen  80 default_server;
      server_name  _;
  
      root  /var/www/html;
      index  index.php;
  
      location / {
        try_files  $uri $uri/ =404;
      }
  
      location ~ \.php$ {
        include fastcgi_params;
        fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
        fastcgi_param  SERVER_SOFTWARE    nginx;
        fastcgi_param  QUERY_STRING       $query_string;
        fastcgi_param  REQUEST_METHOD     $request_method;
        fastcgi_param  CONTENT_TYPE       $content_type;
        fastcgi_param  CONTENT_LENGTH     $content_length;
        fastcgi_param  DOCUMENT_ROOT      $document_root;
        fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
        fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
        fastcgi_param  REQUEST_URI        $request_uri;
        fastcgi_param  DOCUMENT_URI       $document_uri;
        fastcgi_param  SERVER_PROTOCOL    $server_protocol;
        fastcgi_param  REMOTE_ADDR        $remote_addr;
        fastcgi_param  REMOTE_PORT        $remote_port;
        fastcgi_param  SERVER_ADDR        $server_addr;
        fastcgi_param  SERVER_PORT        $server_port;
        fastcgi_param  SERVER_NAME        $server_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_read_timeout 600;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_intercept_errors  on;
        fastcgi_pass  moodle_mysql_alpine:9000;
      }
    }
  }
  </code></pre>
  
  <p>Still I get redirection loop.</p>
  
  <h1>Edit 2:</h1>
  
  <p>As requested with the command <code>curl -iv http://0.0.0.0:7070</code> I get the following response:</p>
  
  <pre><code>* Rebuilt URL to: http://0.0.0.0:7070/
  *   Trying 0.0.0.0...
  * Connected to 0.0.0.0 (127.0.0.1) port 7070 (#0)
  &gt; GET / HTTP/1.1
  &gt; Host: 0.0.0.0:7070
  &gt; User-Agent: curl/7.47.0
  &gt; Accept: */*
  &gt; 
  &lt; HTTP/1.1 303 See Other
  HTTP/1.1 303 See Other
  &lt; Server: nginx/1.13.3
  Server: nginx/1.13.3
  &lt; Date: Sun, 01 Oct 2017 09:41:21 GMT
  Date: Sun, 01 Oct 2017 09:41:21 GMT
  &lt; Content-Type: text/html; charset=UTF-8
  Content-Type: text/html; charset=UTF-8
  &lt; Transfer-Encoding: chunked
  Transfer-Encoding: chunked
  &lt; Connection: keep-alive
  Connection: keep-alive
  &lt; X-Powered-By: PHP/7.0.23
  X-Powered-By: PHP/7.0.23
  &lt; Location: http://0.0.0.0:7070
  Location: http://0.0.0.0:7070
  &lt; Content-Language: en
  Content-Language: en
  
  &lt; 
  &lt;!DOCTYPE html&gt;
  &lt;html  lang="en" xml:lang="en"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  
  &lt;title&gt;Redirect&lt;/title&gt;
  * Connection #0 to host 0.0.0.0 left intact
  &lt;/head&gt;&lt;body&gt;&lt;div style="margin-top: 3em; margin-left:auto; margin-right:auto; text-align:center;"&gt;This page should automatically redirect. If nothing is happening please use the continue link below.&lt;br /&gt;&lt;a href="http://0.0.0.0:7070"&gt;Continue&lt;/a&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;
  </code></pre>
  
  <h1>Edit 3:</h1>
  
  <p>I tried to use the configuration based on <a href="https://docs.moodle.org/29/en/Nginx" rel="nofollow noreferrer">https://docs.moodle.org/29/en/Nginx</a> and resulted this nginx configuration:</p>
  
  <pre class="lang-nginx prettyprint-override"><code>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;
  
    server {
      listen  80 default_server;
      server_name  _;
  
      root  /var/www/html;
      index  index.php;
  
      location / {
        try_files  $uri $uri/ =404;
      }
  
      location ~ [^/]\.php(/|$) {
        fastcgi_split_path_info  ^(.+\.php)(/.+)$;
        fastcgi_index index.php;
        include   fastcgi_params;
        fastcgi_param   PATH_INFO       $fastcgi_path_info;
        fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
  
        fastcgi_pass  moodle_mysql_alpine:9000;
      }
  
      location /dataroot/ {
        internal;
        alias /var/moodledata; # ensure the path ends with /
      }
  
    }
  }
  </code></pre>
  
  <p>But I still get the 303 redirect loop.</p>