11

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.

4

1 回答 1

2

(由 OP 在问题编辑中回答。转换为社区 wiki 答案。请参阅没有答案的问题,但问题在评论中解决(或在聊天中扩展)

OP写道:

我通过将 rewrite 指令放在{server}not in {location}section 中解决了这个问题。在我的场景中,moodle 安装在子文件夹下: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;
        }
        }
        }
于 2015-01-30T19:47:39.423 回答