Nginx + Moodle configuration tips

Nginx + Moodle configuration tips

by Jon Langevin -
Number of replies: 5

Just to preface, we're dropping Centos+Apache+Zend Server CE, to switch to Ubuntu+Nginx+PHP-FPM.

I haven't seen anyone post a (good) solution to make /file.php/ and /user/pix.php/ function properly in Moodle. Here's my solution below.

The problem: Nginx considerings file.php in /file.php/whatever.ext to be a folder. This is a problem, as we need it to be considered as a PHP file.

The solution (this goes within your Moodle nginx website config):

            # If file isn't found
            if (!-e $request_filename) {
                    set $filephp 1;
            }

            # If the missing file is a php folder URL
            if ($request_filename ~ "\.php/") {
                    set $filephp "${filephp}1";
            }

            # Non-existing URL based on PHP script
            # Rewrite the URL to the base PHP script requesting
            if ($filephp = 11) {
                    rewrite  ^(.*)\.php/.*$  /$1.php  last;
                    break;
            }

I'll be posting other tips as I come across them. Anyone else, please post as well smile

Average of ratings: Useful (1)
In reply to Jon Langevin

Re: Nginx + Moodle configuration tips

by Antonio Hdez -

I think I have the same problem, in that file just enter the text exactly.

In /etc/ningx/default
In /etc/nignx/site-enable/default
Or in a file moodle

Thanks for sharing your tips

 

In reply to Jon Langevin

Re: Nginx + Moodle configuration tips

by Frankie Kam -
Picture of Plugin developers

> Just to preface, we're dropping Centos+Apache+Zend Server CE, to switch to
>Ubuntu+Nginx+PHP-FPM.
>

Pray tell WHY?

Frankie

In reply to Jon Langevin

Re: Nginx + Moodle configuration tips

by Joanna Tsai -

 

Yes, just the following in the nginx.conf in accordance with the same domain

rewrite ^/file.php/(.*)$ /file.php?file=/$1 last;
rewrite ^/user/pix.php(.*)$ /user/pix.php?file=/$1 last;

but it doesn't work for moodle 2.0, 'coz the hyperlink file and way is changed,

it displayed like this

Many thanks!

In reply to Jon Langevin

Re: Nginx + Moodle configuration tips

by Chin LH -

I've modified your rewrite rules for Nginx + Moodle 3.0.

    # If file isn't found
    if (!-e $request_filename) {
        set $filephp 1;
    }
    # If the missing file is a php folder URL
    if ($request_filename ~ "\.php/") {
        set $filephp "${filephp}1";
    }
    # Non-existing URL based on PHP script
    # Rewrite the URL to the base PHP script requesting
    if ($filephp = 11) {
        rewrite ^(.*)\.php/(.*)$ $1.php?file=/$2 last;
        break;
    }


In reply to Jon Langevin

Re: Nginx + Moodle configuration tips

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 haven't seen anyone post a (good) solution to make /file.php/ and /user/pix.php/ function properly in Moodle"


Why is that a problem in the first place?