Moodle 2.3与Nginx vs斜杠参数重写

前端之家收集整理的这篇文章主要介绍了Moodle 2.3与Nginx vs斜杠参数重写前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在尝试使用Nginx最新版本设置Moodle 2.3(不是2.5)版本.以前有这方面的建议.其中之一:Moodle 2.0 with Nginx backend.

显然,任何人都知道,Moodle正在使用path_info规则来发布URL,如下所示:http://example.com/moodle/pluginfile.php/26/mod_scorm/content/1/index.html.为了避免所有这个恶梦,Moodle提供在UI中禁用“Slash参数”.哪个是伟大的但是对于尽管前一个选项强制“斜杠参数”的SCORM播放器.所以在禁用“斜杠论证”中,一切正常.但我唯一的目标是使用SCORM播放器.

我试图从上面的链接使用重写规则:

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

这在2.3-2.5版本中不起作用.我认为它的工作在1.9.
现在Moodle正在使用不同的路径:

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

一些Nginx规则:

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;
}

请指教如何解决这个问题.

最佳答案
(由OP在问题编辑中回答)转换为社区wiki答案见Question with no answers,but issue solved in the comments (or extended in chat))

OP写道:

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;
        }
        }
        }
原文链接:https://www.f2er.com/nginx/434665.html

猜你在找的Nginx相关文章