Moodle 3.0 - CSS 和 Javascript 不加载 - 对 NGINX 的请求与真实路径不兼容
Posted
技术标签:
【中文标题】Moodle 3.0 - CSS 和 Javascript 不加载 - 对 NGINX 的请求与真实路径不兼容【英文标题】:Moodle 3.0 - CSS and Javascript don't load - Requests to NGINX aren't compatible with the real paths 【发布时间】:2017-09-21 17:10:00 【问题描述】:我的配置:
Ubuntu 14.04 nginx 1.4.6 php 5.5.9 Moodle 3.0我已经通过浏览器完成了 Moodle 3.0 的安装,并且没有加载 css 或 javascript。这是 NGINX 错误日志:
2017/04/24 20:48:23 [error] 3277#0: *601 open() "/var/www/html/moodle/theme/image.php/clean/core/1493057621/moodlelogo" failed (20: Not a directory), client: 10.0.2.2, server: localhost, request: "GET /theme/image.php/clean/core/1493057621/moodlelogo HTTP/1.1", host: "localhost:8080", referrer: "http://localhost:8080/index.php"
2017/04/24 20:48:23 [error] 3277#0: *601 open() "/var/www/html/moodle/lib/javascript.php/1493057621/lib/requirejs/require.min.js" failed (20: Not a directory), client: 10.0.2.2, server: localhost, request: "GET /lib/javascript.php/1493057621/lib/requirejs/require.min.js HTTP/1.1", host: "localhost:8080", referrer: "http://localhost:8080/index.php"
2017/04/24 20:48:23 [error] 3277#0: *601 open() "/var/www/html/moodle/theme/javascript.php/clean/1493057621/footer" failed (20: Not a directory), client: 10.0.2.2, server: localhost, request: "GET /theme/javascript.php/clean/1493057621/footer HTTP/1.1", host: "localhost:8080", referrer: "http://localhost:8080/index.php"
2017/04/24 20:48:24 [error] 3277#0: *609 open() "/var/www/html/moodle/theme/styles.php/clean/1493057621/all" failed (20: Not a directory), client: 10.0.2.2, server: localhost, request: "GET /theme/styles.php/clean/1493057621/all HTTP/1.1", host: "localhost:8080", referrer: "http://localhost:8080/index.php"
2017/04/24 20:48:24 [error] 3277#0: *611 open() "/var/www/html/moodle/lib/javascript.php/1493057621/lib/javascript-static.js" failed (20: Not a directory), client: 10.0.2.2, server: localhost, request: "GET /lib/javascript.php/1493057621/lib/javascript-static.js HTTP/1.1", host: "localhost:8080", referrer: "http://localhost:8080/index.php"
2017/04/24 20:48:24 [error] 3277#0: *611 open() "/var/www/html/moodle/theme/image.php/clean/core/1493057621/moodlelogo" failed (20: Not a directory), client: 10.0.2.2, server: localhost, request: "GET /theme/image.php/clean/core/1493057621/moodlelogo HTTP/1.1", host: "localhost:8080", referrer: "http://localhost:8080/index.php"
2017/04/24 20:48:24 [error] 3277#0: *606 open() "/var/www/html/moodle/lib/javascript.php/1493057621/lib/requirejs/require.min.js" failed (20: Not a directory), client: 10.0.2.2, server: localhost, request: "GET /lib/javascript.php/1493057621/lib/requirejs/require.min.js HTTP/1.1", host: "localhost:8080", referrer: "http://localhost:8080/index.php"
2017/04/24 20:48:24 [error] 3277#0: *606 open() "/var/www/html/moodle/theme/javascript.php/clean/1493057621/footer" failed (20: Not a directory), client: 10.0.2.2, server: localhost, request: "GET /theme/javascript.php/clean/1493057621/footer HTTP/1.1", host: "localhost:8080", referrer: "http://localhost:8080/index.php"
2017/04/24 20:48:25 [error] 3277#0: *609 open() "/var/www/html/moodle/lib/javascript.php/1493057621/lib/javascript-static.js" failed (20: Not a directory), client: 10.0.2.2, server: localhost, request: "GET /lib/javascript.php/1493057621/lib/javascript-static.js HTTP/1.1", host: "localhost:8080", referrer: "http://localhost:8080/index.php"
2017/04/24 20:48:25 [error] 3277#0: *609 open() "/var/www/html/moodle/theme/image.php/clean/core/1493057621/moodlelogo" failed (20: Not a directory), client: 10.0.2.2, server: localhost, request: "GET /theme/image.php/clean/core/1493057621/moodlelogo HTTP/1.1", host: "localhost:8080", referrer: "http://localhost:8080/index.php"
2017/04/24 20:48:25 [error] 3277#0: *609 open() "/var/www/html/moodle/lib/javascript.php/1493057621/lib/requirejs/require.min.js" failed (20: Not a directory), client: 10.0.2.2, server: localhost, request: "GET /lib/javascript.php/1493057621/lib/requirejs/require.min.js HTTP/1.1", host: "localhost:8080", referrer: "http://localhost:8080/index.php"
2017/04/24 20:48:25 [error] 3277#0: *609 open() "/var/www/html/moodle/theme/javascript.php/clean/1493057621/footer" failed (20: Not a directory), client: 10.0.2.2, server: localhost, request: "GET /theme/javascript.php/clean/1493057621/footer HTTP/1.1", host: "localhost:8080", referrer: "http://localhost:8080/index.php"
似乎该路径将某些 .php 文件视为目录。 这是我的服务器配置:
server
listen 8080;
server_name localhost;
# Root #
root /var/www/html/moodle/;
index index.php index.html index.htm;
location ~ \.php$
if (!-f $document_root$fastcgi_script_name)
rewrite ^ 404;
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
我已经尝试过这些解决方案:
Solution 1
Solution 2
他们没有工作......
【问题讨论】:
您的错误消息显示带有路径信息的.php
脚本,但您的配置不支持路径信息。请参阅this recipe 获取指导。
@RichardSmith 我阅读了您发送的文章,对我的代码进行了一些更改,但它几乎与我所做的相同,但什么也没发生。我的代码的 fastcgi_split_path_info 与文章中的略有不同。我仍然有同样的问题...
您的 location ~ \.php$
语句只接受没有路径信息的 URI。最后的$
意味着他们在.php
之后完成。这也许就是你需要改变的全部。
@RichardSmith 伙计,我尝试了您的修复方法,但没有成功。问题是:路径必须以 .php 结尾,否则后面的斜线会告诉解释器 php 文件是一个目录。这很奇怪......
你找到解决办法了吗?
【参考方案1】:
这是我的普通 nginx 配置,适用于 moodle >=3.1
server
listen 80;
server_name someservername.com;
root /var/www;
index index.php index.html index.htm;
location ~ [^/]\.php(/|$)
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
【讨论】:
对我有用的是location ~ [^/]\.php(/|$)
和fastcgi_split_path_info ^(.+\.php)(/.+)$;
部分。
对我来说,fastcgi_param PATH_INFO $fastcgi_path_info;
解决了这个问题【参考方案2】:
请在您的 nginx.conf 文件的服务器部分添加以下配置代码。
location /
root /var/www/yourwebsite.com;
index index.php index.html index.htm;
# moodle rewrite rules
rewrite ^/(.*.php)(/)(.*)$ /$1?file=/$3 last;
# php parsing
location ~ .php$
root /var/www/yourwebsite.com;
try_files $uri =404;
fastcgi_pass unix:/tmp/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_buffer_size 128k;
fastcgi_buffers 256 4k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
【讨论】:
绝对解决了我的问题。谢谢!!以上是关于Moodle 3.0 - CSS 和 Javascript 不加载 - 对 NGINX 的请求与真实路径不兼容的主要内容,如果未能解决你的问题,请参考以下文章
css 使用theme_more为Moodle的用户菜单设置样式
怎样在 Ubuntu 下安装 Moodle(“魔灯”) | Linux 中国