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播放器.

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

  1. 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规则:

  1. location ^~ /moodle {
  2. 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)${
  3. add_header Access-Control-Allow-Origin *;
  4. access_log off;
  5. expires 30d;
  6. tcp_nodelay off;
  7. try_files $uri =404;
  8. }
  9. location ~* ^/moodle/.*\.PHP${
  10. include includes/fastcgi_params.conf;
  11. try_files $uri @dynamic;
  12. fastcgi_split_path_info ^(.+\.PHP)(/.+)$;
  13. fastcgi_param PATH_INFO $fastcgi_path_info;
  14. fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
  15. fastcgi_read_timeout 1200;
  16. fastcgi_keep_conn on;
  17. fastcgi_pass 127.0.0.1:9090;
  18. }
  19. rewrite (^.*\.PHP)(/.*) $1 last;
  20. }

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

最佳答案
(由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.

  1. server {
  2. server_name example.com www.example.com;
  3. rewrite ^/moodle/(.*\.PHP)(/)(.*)$/moodle/$1?file=/$3 last;
  4. location ^~ /moodle {
  5. try_files $uri $uri/ /index.PHP?q=$request_uri;
  6. index index.PHP index.html index.htm;
  7. location ~ \.PHP${
  8. fastcgi_split_path_info ^(.+\.PHP)(/.+)$;
  9. fastcgi_pass 127.0.0.1:9090;
  10. include includes/fastcgi_params.conf;
  11. }
  12. }
  13. }

猜你在找的Nginx相关文章