Installing and upgrading help

Redirection from apache2 server to nginx reverse proxy server w moodle 3.3

 
Picture of Carolynn Bellavance
Redirection from apache2 server to nginx reverse proxy server w moodle 3.3
 

When I go to https://domain.com/moodle/ it gives me the index page as if I was not logged in but when I click on the links it goes to https://192.168.0.26/whatever_comes_next

If I go to https://domain.com/moodle/login/index.php it works, but the moment I login it goes back to the ip address,

This only happens with moodle, all the other servers are available so I do not know where else I can ask for help. I am now running in circle editing config after config trying to figure out which one is missing.... 

This as worked in the past as the site was available before a failure of all the servers. I had to reboot everything and remake the the nginx server. Everything was copy/pasta of the last config but it still does not work as it did before.


Moodle config.php :

<?php  // Moodle configuration file

unset($CFG);
global $CFG;
$CFG = new stdClass();

$CFG->dbtype    = 'mysqli';
$CFG->upgradekey = 'stuff';
$CFG->dblibrary = 'native';
$CFG->dbhost    = 'localhost';
$CFG->dbname    = 'moodle';
$CFG->dbuser    = 'user';
$CFG->dbpass    = 'password';
$CFG->prefix    = 'mdl_';
$CFG->dboptions = array (
  'dbpersist' => 0,
  'dbport' => '',
  'dbsocket' => '',
);

$CFG->wwwroot   = 'https://192.168.0.26';
$CFG->dirroot = '/var/www/moodle';
$CFG->dataroot  = '/var/moodledata';
$CFG->admin     = 'admin';

$CFG->directorypermissions = 02777;
require_once(dirname(__FILE__) . '/lib/setup.php');
$CFG->reverseproxy = true;
//$CFG->sslproxy = true;


Nginx conf :

server {
        listen 80;
        server_name domain.com;
        return 301 https://$host$request_uri;
}

server {
       listen 443 ssl http2;
        server_name domain.com;

        root   /var/www/domain;
        index index.php index.html index.htm;

        ssl on;
        ssl_certificate                 /etc/ssl/certs/www.domain.com.crt;
        ssl_certificate_key             /etc/ssl/private/www.domain.com.key;
        ssl_session_cache               builtin:1000    shared:SSL:10m;
        ssl_protocols                   TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers                     HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;>
        ssl_prefer_server_ciphers       on;

        access_log      /var/log/nginx/domain.access.log;
        error_log       /var/log/nginx/domain.error.log;

        error_page 404 /custom_404.html;
        location = /custom_404.html {
                root /var/www/domain/;
                internal;
        }

        error_page 500 502 503 504 /custom_50x.html;
        location = /custom_50x.html {
                root /var/www/domain/;
                internal;
        }

        location /.well-known/acme-challenge/ {
                alias /var/www/domain/;
                try_files $uri =404;
        }

        location / {
                try_files $uri $uri/ =404;
        }

        location ~ /\. {
                deny all;
        }

        location /moodle/ {
                proxy_pass              https://192.168.0.26/;
                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_read_timeout      90;
                }


Moodle log file : 

==> /var/log/apache2/access.log <==

192.168.1.201 - - [10/Jan/2018:10:07:25 -0500] "GET / HTTP/1.0" 200 7583 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36"

192.168.0.160 - - [10/Jan/2018:10:07:25 -0500] "GET /theme/yui_combo.php?rollup/3.17.2/yui-moodlesimple-min.css HTTP/1.1" 200 1758 "https://domain.com/moodle/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36"

192.168.0.160 - - [10/Jan/2018:10:07:25 -0500] "GET /theme/styles.php/boost/1499973071/all HTTP/1.1" 200 110212 "https://domain.com/moodle/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36"

192.168.0.160 - - [10/Jan/2018:10:07:25 -0500] "GET /theme/styles.php/boost/blocks/configurable_reports/js/codemirror/lib/codemirror.css HTTP/1.1" 404 257 "https://domain.com/moodle/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36"

192.168..0.160 - - [10/Jan/2018:10:07:25 -0500] "GET /theme/styles.php/boost/blocks/configurable_reports/js/datatables/media/css/jquery.dataTables.css HTTP/1.1" 404 257 "https://domain.com/moodle/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36"

192.168.0.160 - - [10/Jan/2018:10:07:25 -0500] "GET /theme/styles.php/boost/blocks/configurable_reports/js/codemirror/addon/display/fullscreen.css HTTP/1.1" 404 409 "https://domain.com/moodle/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36"

192.168.0.160 - - [10/Jan/2018:10:07:25 -0500] "GET /moodle/theme/image.php/boost/core/1499973071/t/collapsed_empty HTTP/1.1" 404 765 "https://192.168.0.26/theme/styles.php/boost/1499973071/all" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36"

192.168.0.160 - - [10/Jan/2018:10:07:25 -0500] "GET /moodle/theme/image.php/boost/core/1499973071/t/collapsed HTTP/1.1" 404 759 "https://192.168.0.26/theme/styles.php/boost/1499973071/all" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36"

192.168.0.160 - - [10/Jan/2018:10:07:25 -0500] "GET /moodle/theme/image.php/boost/core/1499973071/i/course HTTP/1.1" 404 756 "https://192.168.0.26/theme/styles.php/boost/1499973071/all" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36"

192.168.0.160 - - [10/Jan/2018:10:07:25 -0500] "GET /theme/yui_combo.php?m/1499973071/core/event/event-min.js&m/1499973071/filter_mathjaxloader/loader/loader-min.js HTTP/1.1" 200 1398 "https://domain.com/moodle/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36"

192.168.0.160 - - [10/Jan/2018:10:07:25 -0500] "GET /theme/yui_combo.php?m/1499973071/course/categoryexpander/categoryexpander-min.js HTTP/1.1" 200 2479 "https://domain.com/moodle/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36"

192.168.0.160 - - [10/Jan/2018:10:07:25 -0500] "GET /lib/requirejs.php/1499973071/core/first.js HTTP/1.1" 200 111696 "https://domain.com/moodle/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36"

192.168.0.160 - - [10/Jan/2018:10:07:25 -0500] "GET /lib/javascript.php/1499973071/lib/requirejs/jquery-private.js HTTP/1.1" 200 670 "https://domain.com/moodle/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36"

192.168.0.160 - - [10/Jan/2018:10:07:25 -0500] "GET /lib/javascript.php/1499973071/lib/jquery/jquery-3.1.0.min.js HTTP/1.1" 200 30756 "https://domain.com/moodle/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36"

192.168.0.160 - - [10/Jan/2018:10:07:25 -0500] "GET /theme/yui_combo.php?3.17.2/event-mousewheel/event-mousewheel-min.js&3.17.2/event-resize/event-resize-min.js&3.17.2/event-hover/event-hover-min.js&3.17.2/event-touch/event-touch-min.js&3.17.2/event-move/event-move-min.js&3.17.2/event-flick/event-flick-min.js&3.17.2/event-valuechange/event-valuechange-min.js&3.17.2/event-tap/event-tap-min.js HTTP/1.1" 200 5382 "https://domain.com/moodle/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36"


==> /var/log/apache2/error.log <==

[Wed Jan 10 10:07:25.570442 2018] [:error] [pid 27188] [client 192.168.0.160:39224] Default exception handler: Erreur de programmation d\xc3\xa9tect\xc3\xa9e. Ceci doit \xc3\xaatre corrig\xc3\xa9 par un programmeur\xc2\xa0: Invalid json in request: Syntax error Debug: \nError code: codingerror\n* line 42 of /lib/ajax/service.php: coding_exception thrown\n


==> /var/log/apache2/access.log <==

192.168.0.160 - - [10/Jan/2018:10:07:25 -0500] "OPTIONS /lib/ajax/service.php?sesskey=2mw4FF7tAe&info=core_fetch_notifications HTTP/1.1" 404 24237 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36"


Nginx log file : 

192.168.0.160 - - [10/Jan/2018:10:06:53 -0500] "GET /moodle/ HTTP/2.0" 200 7193 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36"



If I change $CFG->wwwroot to https://domain.com/moodle it gives me error :

ERR_TOO_MANY_REDIRECTS


Nginx log file : 

192.168.0.160 - - [10/Jan/2018:10:13:26 -0500] "GET /moodle/ HTTP/2.0" 303 636 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36"


Moodle log file : 
192.168.1.201 - - [10/Jan/2018:10:13:26 -0500] "GET / HTTP/1.0" 303 872 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36"

 
Average of ratings: -
Picture of Carolynn Bellavance
Re: Redirection from apache2 server to nginx reverse proxy server w moodle 3.3
 

I edited the nginx conf file to take out the / at the end of the proxy_pass

proxy_pass http://192.168.0.26:8080;

I now get a 404 error from both nginx and moodle :

192.168.0.19 - - [12/Jan/2018:13:29:59 -0500] "GET /moodle/ HTTP/1.0" 404 464 "https://example.com/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36"

 
Average of ratings: -
Picture of Emma Richardson
Re: Redirection from apache2 server to nginx reverse proxy server w moodle 3.3
Documentation writersParticularly helpful MoodlersPlugin developers

Try sending the proxy pass to the domain address instead of the ip and just use local dns or host to send it to the right ip.  That is how I have my nginx set up.

 
Average of ratings: -
Picture of Matteo Scaramuccia
Re: Redirection from apache2 server to nginx reverse proxy server w moodle 3.3
Core developersParticularly helpful MoodlersPlugin developers

Hi Carolynn,
why not removing Apache and let PHP-FPM, installed where Apache is running now, collaborate w/ nginx to serve your Moodle instance?
I mean: https://docs.moodle.org/34/en/Nginx . Unless you're using X-Sendfilehttps://docs.moodle.org/34/en/Performance_recommendations#X-Sendfile .

BTW, you need to expose your public hostname in $CFG->wwwroot and use $CFG->reverseproxy = true; and avoid the trailing slash in both location and proxy_pass.

Note: 303 is the HTTP Status used by Moodle to redirect to the login page. When changing the configuration, please purge all caches, hopefully the /cache and /localcache folders in the moodle data folder ($CFG->dataroot) if you don't use any other cache store; otherwise, use the CLI, https://docs.moodle.org/34/en/Administration_via_command_line#Purge_caches .

HTH,
Matteo

 
Average of ratings: Useful (2)
Picture of Carolynn Bellavance
Re: Redirection from apache2 server to nginx reverse proxy server w moodle 3.3
 

I would love to change the configuration but I am to work with what I have right now before trying  anything "new". The nginx is configured in a way to have all our locations in the same conf file, if I change it, it will also change for all our sites and without testing what config works for everything without any downtime I cannot do it for moodle. 


I do not know what you mean by "exposing" my hostname ?
CFG->reverseproxy = true is already at true, but I did take out the trailing slashes, as I wrote in my last message, it gives out a 404 error "/moodle/ not found".


Tried Emma's suggestion but it only gives these logs on nginx : 

==> /var/log/nginx/domain.access.log <==

192.168.0.160 - - [15/Jan/2018:08:32:08 -0500] "GET /moodle/ HTTP/2.0" 499 0 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36"

==> /var/log/nginx/domain.error.log <==

2018/01/15 08:33:08 [error] 40436#40436: *41130 upstream timed out (110: Connection timed out) while connecting to upstream, client: 192.168.0.160, server: example.com, request: "GET /moodle/ HTTP/2.0", upstream: "https://192.168.0.4:443/moodle/", host: "example.com"


EDIT: Thank you both of you for your help. Figured out the 404 error was becasue the apache conf on the moodle server directed to /var/www/moodle/ instead of /var/www/. It is now working as it should.

 
Average of ratings: -
Picture of Le Minh Tuan
Reply: Redirection from apache2 server to nginx reverse proxy server w moodle 3.3
 

you can try this line proxy_set_header Host $host; in location /moodle/ . It's work for me.

 
Average of ratings: -