Nginx (fronteend) + Apache2 (backend) + Moodle

Nginx (fronteend) + Apache2 (backend) + Moodle

by Ricardo Caiado -
Number of replies: 16
Picture of Particularly helpful Moodlers
Hello everyone,

I just installed Nginx as a frontend server. After much searching the internet I could not configure it in order to get everything 100%. For example, some images do not appear and some links to PDF files are broken.

I am in search of a "nginx.conf" with the settings to use with Moodle.

Any idea?

All the best,

Ricardo
Average of ratings: -
In reply to Ricardo Caiado

Re: Nginx (fronteend) + Apache2 (backend) + Moodle

by Jon Langevin -
Post your existing nginx.conf, and any access log and error log entries from your log files, maybe we can help you tweak.
In reply to Ricardo Caiado

Re: Nginx (fronteend) + Apache2 (backend) + Moodle

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
The prob could be that Nginx is also a reverse proxy. As pointed out, the config would be helpful for the diagnosis.
In reply to Ricardo Caiado

Re: Nginx (fronteend) + Apache2 (backend) + Moodle

by Jon Langevin -
Just a thought, were your images and PDF files working properly prior to installing Nginx as a frontend?

It may be a configuration error in Moodle. I've had a similar problem in straight up Apache and Nginx solutions (not a frontend/backend solution, each as a separate webserver), if there are extra white lines at the end of config.php , images and files will disappear.

This is because file.php, which serves up a variety of images and files dynamically, will break when there are blank lines at the end of config.php.

So that could be your issue.
In reply to Jon Langevin

Re: Nginx (fronteend) + Apache2 (backend) + Moodle

by Ricardo Caiado -
Picture of Particularly helpful Moodlers
Jon,

Moodle is working just fine runnibg under Apache2 without NginX.

The problem shows up only when I start NginX. And it makes me think it's a NginX configuration tunning.

I'll try what you said in "http://moodle.org/mod/forum/discuss.php?d=157382".

Ricardo




In reply to Ricardo Caiado

Re: Nginx (fronteend) + Apache2 (backend) + Moodle

by Jon Langevin -
Hi Ricardo, please note that my other post is regarding the complete removal of Apache2 from the picture.
If you need any help with configuring your server, let me know. I'm running Ubuntu 10.04, Nginx, and PHP-FPM, and I can share my configs with you.

Cheers
In reply to Jon Langevin

Re: Nginx (fronteend) + Apache2 (backend) + Moodle

by Ricardo Caiado -
Picture of Particularly helpful Moodlers
Jon,

That would br GREAT!!!

Thanks in advance !!!

Ricardo



In reply to Jon Langevin

Re: Nginx (fronteend) + Apache2 (backend) + Moodle

by Antonio Estrada -

OMG you were right. After spending nearly 2 days banging my head against the wall trying NGINX rewrites, and having them not work, the error was a space at the end of config.php . 

In reply to Ricardo Caiado

Re: Nginx (fronteend) + Apache2 (backend) + Moodle

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
I'm just thinking that many people will never have heard of nginx. It may be worth a few lines to explain why you have chosen to use this. Especially as it will no doubt cause you some pain compared to running a more conventional system.
In reply to Howard Miller

Re: Nginx (fronteend) + Apache2 (backend) + Moodle

by Jon Langevin -
Administering Nginx is actually quite simple.
While there is a small learning curve (think of when you first attempted to manually host an Apache website), I've had less issues with Nginx than Apache, especially with regards to troubleshooting.


But my own reasons for choosing Nginx, would be:
- Speed
- Optimization
- Reliability
- Less bloat (I don't have to go through a config file to remove everything that I don't want, as it comes already lean)


URL rewriting is even simpler in Nginx, at least, from the perspective of a programmer, as the syntax makes more sense.


Nginx's ability to scale well, less ram usage, higher concurrent process handling, etc, are all huge reasons to dump Apache, especially for a system-intensive application such as Moodle.
In reply to Howard Miller

Re: Nginx (fronteend) + Apache2 (backend) + Moodle

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
This sounds almost exactly the same bunch of positives cited for lighttpd.

And.. it's great for small, simple installations but as soon as you want to do anything "interesting" the whole house of cards falls down. Then you find out why Apache has all the "bloat" smile
In reply to Howard Miller

Re: Nginx (fronteend) + Apache2 (backend) + Moodle

by Ricardo Caiado -
Picture of Particularly helpful Moodlers
You mean Nginx as "fronteend" and Apache2 as "backend" is not a good idea?

In reply to Ricardo Caiado

Re: Nginx (fronteend) + Apache2 (backend) + Moodle

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
Hi Ricardo and Jon

> You mean Nginx as "fronteend" and Apache2 as "backend" is not a good idea?

Could you explain this setup in detail? Does it mean, Apache is the "real" webserver for Moodle, Nginx is reverse-proxy and load-balencer, all on different machines?
In reply to Visvanath Ratnaweera

Re: Nginx (fronteend) + Apache2 (backend) + Moodle

by Ricardo Caiado -
Picture of Particularly helpful Moodlers
That´s right. But in my case NginX and Apache are running on the same machine.
In reply to Visvanath Ratnaweera

Re: Nginx (fronteend) + Apache2 (backend) + Moodle

by Jon Langevin -
Correct. This thread is regarding a frontend Nginx server, and a backend Apache server.

You can have multiple backend servers, to which traffic can be controlled by the Nginx frontend.

Your backend can also consist of something other than Apache, such as another Nginx install, or LightHttpd, etc.

You can even run Nginx as the reverse proxy, on the same machine that serves Apache. This way, if you have a website with static files (such as HTML), you can serve the HTML separately from your dynamic content, which is controlled by Apache (but still proxied through Nginx).

The regular frontend/backend setup can function similarly, by just telling Nginx what it can cache on it's reverse proxy (such as images, html, etc), but in this case, you have to be a bit more careful with the rules (to avoid caching a script that you want to remain dynamic).


It's very versatile smile


I personally don't need Apache, so I run Nginx by itself (or with a frontend Nginx proxy for load balancing).
In reply to Howard Miller

Re: Nginx (fronteend) + Apache2 (backend) + Moodle

by Jon Langevin -
LightHttpd is a good alternative to Nginx (according to what I've read), but I've read numerous posts about memory leaks in LightHttpd.


Nginx is great for simple and complex installations, it's actually more flexible than Apache.

For instance, in Apache you can't load conf files in this path: /var/www/*/conf/*.conf (where the first wildcard is each individual vhost folder, and the last wildcard is any configuration file for that vhost)


In the past 2 years, I've had *less* problems with configuration and less stability issues, running Nginx over Apache, and that's while managing servers for various companies (as well as my own servers).
I've also not once encountered a situation where Nginx couldn't provide what I needed.