【问题标题】:Moodle 2.3 with Nginx vs slash argument rewriteMoodle 2.3 与 Nginx vs 斜线参数重写
【发布时间】:2013-08-17 07:08:37
【问题描述】:

我正在尝试使用 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 中禁用“斜线参数”。这是伟大的。但不适用于 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;
}

请告知如何解决这个问题。

【问题讨论】:

  • 您应该将解决方案作为您自己问题的答案并接受它。
  • 另外,能否请您发布您的整个 nginx 配置文件?那将非常有帮助。谢谢!

标签: nginx moodle


【解决方案1】:

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

OP 写道:

我通过将重写指令放在 {server} 而不是 {location} 部分来解决这个问题。在我的场景中,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;
        }
        }
        }

【讨论】:

  • 假设所有包含.php/ 的URL 都使用?file= 重写是错误的,并且可能会导致问题!在pluginfile.php/ 等上创建更具体的匹配会更安全...
猜你喜欢
  • 1970-01-01
  • 2015-06-20
  • 1970-01-01
  • 2021-09-10
  • 1970-01-01
  • 2017-06-30
  • 2018-10-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多