502 Bad Gateway when editing user/editadvanced.php

502 Bad Gateway when editing user/editadvanced.php

by Mohamed Ali -
Number of replies: 12

Since I have upgraded My Moodle from version 2.6 to 3.1.5, I have a a weird issue.

When trying to edit user information user/editadvanced.php it takes a very long time and returns 502 Bad Gateway.

this issue happened randomly, some times it works fine and some times it's just happened.

I didn't change any thing in the configuration

I have tried to add another another IP and add route to try editing the user info behind the firewall but got the same result, some times it works fine and some time the request doesn't reach the server and returns 502 Bad Gateway.

My current Moodle version is 3.1.5 running on CentOS 7.

Please advise.



Average of ratings: -
In reply to Mohamed Ali

Re: 502 Bad Gateway when editing user/editadvanced.php

by Ken Task -
Picture of Particularly helpful Moodlers

Recently discovered a 'hickup' when upgrading sites from 3.0.highest to 3.1.highest.   It appears that Moodle is moving away from the use of Yahoo libraries.   IF the old version you were running had been set to use combo loading and external YUI libraries, in 3.1, one could not set the first one way or the other - code prevented.   But, code prevention didn't actually change the mdl_config table to set those variables to '0' ... ie, off.   Had to do that via direct editing of DB.

The easiest way to disable them is via config.php file.

Add these two lines to config.php:

$CFG->useexternalyui='0';
$CFG->yuicomboloading='0';

Purge your caches ... /moodledata/cache/ and moodledata/localcache/

Then try to go to an edit form.

'spirit of sharing', Ken


In reply to Ken Task

Re: 502 Bad Gateway when editing user/editadvanced.php

by Mohamed Ali -

Thanks Ken.

i have tried this solution but it didn't work with me.

In reply to Mohamed Ali

Re: 502 Bad Gateway when editing user/editadvanced.php

by Ken Task -
Picture of Particularly helpful Moodlers

Bad gateway (502 errors) is, for sure, networking.   Not sure that one can do much just Moodle to fix that - after all it's the resource inside the server, behind the OS firewall, and any network firewall one might have in front of the server itself.

Do have a CentOS 7 sandbox server however.   The new firewall on CentOS 7 much different than CentOS 6 or 5 (iptables)   It now has zones and settings for protocols/ports per zone.  Not only that, but, if you are not hosting this on your own network, it's remotely hosted ... like on Rackspace or something similar ... they too, even with un-managed servers .... are starting to use IPv6.

Suggest installing iptraf on server and running it in a terminal session while from another workstation, accessing Moodle and editing whatever.

In that problem I mentioned ... weird behavoir never before witnessed ... and whose solution was to disable YUI ... the other strange thing ... in Moodle's logs, I'd see the admin user access recording an IPv6 address and not an IPv4 as his access has always shown to Moodle.  In my case, hosted on Rackspace, cannot disable IPv6 ... don't know that Moodle actually supports it ...

So ...

https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-using-firewalld-on-centos-7

Disable IPv6:

https://www.unixmen.com/disable-ipv6-centos-7/

Am by no means a CentOS 7 expert and it's hoped that checking the above might help find the cause of the gateway error.

'spirit of sharing', Ken


In reply to Ken Task

Re: 502 Bad Gateway when editing user/editadvanced.php

by Mohamed Ali -

i did that, but the problem still exist !!!


also when running a cron /path/to/moodle/admin/cli/cron.php i got this error " Conversion failed with error:errorgenerateimage" !


please advise.

In reply to Mohamed Ali

Re: 502 Bad Gateway when editing user/editadvanced.php

by Vivek SM -

For me after upgrading from 2.5 to 3.2 i also got 500 error. then i changed the value according to the files count then no errors.

https://docs.moodle.org/31/en/OPcache

opcache.max_accelerated_files = 8000

did you changed this value to more than 8000

In reply to Mohamed Ali

Re: 502 Bad Gateway when editing user/editadvanced.php

by Vivek SM -

For me after upgrading from 2.5 to 3.2 i also got 500 error. then i changed the value according to the files count then no errors.

https://docs.moodle.org/31/en/OPcache

opcache.max_accelerated_files = 8000

did you changed this value to more than 8000

In reply to Vivek SM

Re: 502 Bad Gateway when editing user/editadvanced.php

by Mohamed Ali -

i have increased it from 4000 to 800 and restarted php-fpm, but the problem still exist !

also the cron problem which is "Conversion failed with error:errorgenerateimage" stil exist !


In reply to Mohamed Ali

Re: 502 Bad Gateway when editing user/editadvanced.php

by Ken Task -
Picture of Particularly helpful Moodlers

The conversion error could be related to unoconv.   Is there a path setting to unoconv in your setup?

Also, I think we might be focused too much on Moodle alone.   CentOS 7 running Apache?  or are you running Nginx?

The 502 Bad Gateway error is illusive.   Google for just that '502 Bad Gateway' and you'll see what I mean.

Does this google search find anything useful for ya?

https://www.google.com/search?q=apache+502+bad+gatway+CentOS+7&ie=utf-8

Since you have CentOS 7 you probably also have ssh access.   In a terminal screen, logged on as root user, issue: top [PRESS ENTER]

Then, using a browser, login to Moodle, go to editing a user like you did before.

In the terminal running top, watch the processes ... you should see a httpd process (apache if running apache) shoot to the top of top and top will show how much memory it' using and how much of the CPU that process is using.   Is that one process pegging the CPU at 100%?  then down to 99.X% then back up to 100%?  Until you see the error in the browser?

I also suggested installing iptraf.   Did you install iptraf?   Did you run iptraf?

'spirit of sharing', Ken



In reply to Ken Task

Re: 502 Bad Gateway when editing user/editadvanced.php

by Mohamed Ali -

Thanks for your reply Ken.

We use Nginx and php-fpm.

I'm a linux system engineer, so i have a strong background in linux and the apps running on it, but still have no idea what's happening here smile

The CPU load is very normal, and yes i have installed iptraf, also i have checked the firewall, this is not a network or load issue, i think this is an application issue which.


In reply to Mohamed Ali

Re: 502 Bad Gateway when editing user/editadvanced.php

by Ken Task -
Picture of Particularly helpful Moodlers

Well, am not an engineer and don't run your combo, but do run CentOS 7 and have versions 3.0, 3.1, 3.2, and 3.3 running on a server with no such errors so am not sure it's code.

This is old, but ...

https://stackoverflow.com/questions/10003978/php-fpm-and-nginx-502-bad-gateway

'spirit of sharing', Ken


In reply to Ken Task

Re: 502 Bad Gateway when editing user/editadvanced.php

by Mohamed Ali -

Thanks Ken.

The problem still exist !

should i upgrade to the latest version ? would this help ?

In reply to Mohamed Ali

Re: 502 Bad Gateway when editing user/editadvanced.php

by Ken Task -
Picture of Particularly helpful Moodlers

I don't think upgrading is going to solve the problem.  The 502 Bad Gateway error appears to be one of Nginx configuration ... and/or php-fpm.   That Google search for that error showed links to various forums, etc. and if you looked at them, even if not about moodle, all of them were discussions about Nginx config.

Concentrate on config of nginx and php-fpm.   Check the error logs of nginx.

Like I said, don't run nginx/php-fpm so have never seen a 502 Bad gateway error.   Not saying you need to switch to something else ... but will say tnat I tinkered with nginx/php-fpm this weekend on a tinker box.   That combo does use or could use a proxy config ... right on the server itself.   Didn't get to the point of installing a Moodle on the tinker box ... didn't really need to ... 8 Gig Rackspace box with only the DB's for Moodle installed and tweaked via Tuner didn't gain the significant memory I was seeking.

Do know that nginx is harder to configure and appears to require definitions of a lot of blocks ... even for little things.   No htaccess and some other minor things.

Maybe an Nginx expert will pop in here and help!!! ;)

'spirit of sharing', Ken