Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moodle 2.3 with Nginx vs slash argument rewrite

Tags:

nginx

moodle

I'm trying to setup Moodle 2.3 (not 2.5) ver with nginx latest build. There was some advice on this site before. One of them: Moodle 2.0 with Nginx backend.

Apparently as anybody knows, Moodle is using path_info rules to post URL's like this: http://example.com/moodle/pluginfile.php/26/mod_scorm/content/1/index.html. To escape all this nightmare, Moodle is offering to disable "Slash arguments" in UI. Which is great. But not for SCORM player which is forcing "Slash argument" despite the previous option. So with disabled "Slash arguments" everything is working and normal. But my only goal is to use SCORM player.

I tried to use the rewrite rule from the link above:

rewrite ^(.*\.php)(/)(.*)$ $1?file=/$3 last;

which is not working in 2.3-2.5 ver. I assume it worked in 1.9. Now Moodle is using different path:

http://example.com/moodle/pluginfile.php/26/mod_scorm/content/1/index.html

Some of nginx rules:

location ^~ /moodle {
     location ~*    ^.+\.(?:css|js|htc|xml|jpe?g|gif|png|ico|bmp|svg|swf|pdf|docx?|xlsx?|tiff?|txt|rtf|cgi|bat|pl|dll|aspx?|class|otf|ttf|woff|eot|less)$ {
         add_header  Access-Control-Allow-Origin *;
         access_log off;
         expires 30d;
         tcp_nodelay off;
         try_files $uri =404;
     }
     location ~* ^/moodle/.*\.php$ {
         include      includes/fastcgi_params.conf;
         try_files $uri @dynamic;
         fastcgi_split_path_info ^(.+\.php)(/.+)$;  
         fastcgi_param  PATH_INFO       $fastcgi_path_info;
         fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
         fastcgi_read_timeout 1200;
         fastcgi_keep_conn on;
         fastcgi_pass 127.0.0.1:9090;

     }
     rewrite (^.*\.php)(/.*) $1 last;
}

Please advise how to solve this.

like image 317
John Riviera Avatar asked Aug 15 '13 05:08

John Riviera


1 Answers

(Answered by the OP in a question edit. Converted to a community wiki answer. See Question with no answers, but issue solved in the comments (or extended in chat) )

The OP wrote:

I solved this by putting rewrite directive in {server} not in {location} section. In my scenario moodle is installed under subfolder: example.com/moodle.

server {
     server_name  example.com www.example.com;
     rewrite ^/moodle/(.*\.php)(/)(.*)$ /moodle/$1?file=/$3 last;

  location ^~ /moodle {
     try_files $uri $uri/ /index.php?q=$request_uri;
     index index.php index.html index.htm;

  location ~ \.php$ {
     fastcgi_split_path_info ^(.+\.php)(/.+)$;
     fastcgi_pass 127.0.0.1:9090;   
     include      includes/fastcgi_params.conf;
        }
        }
        }
like image 66
2 revs Avatar answered Jan 03 '23 20:01

2 revs