当用户在我们的 Drupal 网站上填写表单、附加图片并保存时,我们注意到了这个错误。为了确定根本原因(我预计这是所有权或目录权限问题)。我在笔记本电脑上重新创建了确切的文件夹结构。部署了网站并尝试提交表单。遇到了同样的问题。错误日志包含以下条目
2016/06/29 21:29:28 [error] 9419#0: *13 directory index of "/home/sridhar/public_html/pg4me/public/sites/default/files/" is forbidden, client: 127.0.0.1, server: pg4me, request: "GET /sites/default/files/ HTTP/1.1", host: "pg4me", referrer: "http://pg4me/newproperty"
我检查了目录结构的所有权和权限
namei -l /home/sridhar/public_html/pg4me/public/sites/all/modules/
f: /home/sridhar/public_html/pg4me/public/sites/default/files
drwxr-xr-x root root /
drwxr-xr-x root root home
drwxrwxr-x sridhar sridhar sridhar
drwxrwxr-x sridhar sridhar public_html
drwxr-xr-x sridhar sridhar pg4me
drwxr-xr-x sridhar sridhar public
drwxr-xr-x sridhar sridhar sites
drwxr-xr-x sridhar sridhar default
drwxrwxrwx sridhar sridhar files
所有上行目录都具有可执行权限,文件目录具有读取、写入和执行权限(虽然不太安全,但必须提供 777 来检查其是否正常工作)。NGINX 作为 www-data 运行。
/etc/nginx/sites-available 中的 vhost 配置有以下条目
server {
listen pg4me;
server_name pg4me;
root /home/sridhar/public_html/pg4me/public;
index index.php index.html index.htm;
keepalive_timeout 70;
access_log /home/sridhar/public_html/pg4me/log/access.log;
error_log /home/sridhar/public_html/pg4me/log/error.log;
# Make site accessible from http://localhost/
location / {
try_files $uri $uri/ @rewrite;
expires max;
}
location @rewrite {
rewrite ^ /index.php;
}
location ~ \.php$ {
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;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
由于错误消息表明目录列表错误,因此我将以下内容添加到我的 vhost nginx 配置中
location /home/sridhar/public_html/pg4me/public/sites/default/files/ {
autoindex on;
}
但它没有效果。我绞尽脑汁尝试了堆栈跟踪
root@sridhar-Aspire-5745:/home/sridhar/public_html# strace -p 9419 -p 9420 -p 9421 -p 9422 -e trace=file -f
Process 9419 attached
Process 9420 attached
Process 9421 attached
Process 9422 attached
[pid 9419] stat64("/home/sridhar/public_html/pg4me/public/newproperty", 0xbfc6c110) = -1 ENOENT (No such file or directory)
[pid 9419] stat64("/home/sridhar/public_html/pg4me/public/newproperty", 0xbfc6c110) = -1 ENOENT (No such file or directory)
[pid 9419] stat64("/home/sridhar/public_html/pg4me/public/sites/default/files/", {st_mode=S_IFDIR|0777, st_size=69632, ...}) = 0
[pid 9419] stat64("/home/sridhar/public_html/pg4me/public/sites/default/files/", {st_mode=S_IFDIR|0777, st_size=69632, ...}) = 0
[pid 9419] stat64("/home/sridhar/public_html/pg4me/public/sites/default/files/index.php", 0xbfc6c090) = -1 ENOENT (No such file or directory)
[pid 9419] stat64("/home/sridhar/public_html/pg4me/public/sites/default/files", {st_mode=S_IFDIR|0777, st_size=69632, ...}) = 0
[pid 9419] stat64("/home/sridhar/public_html/pg4me/public/sites/default/files/index.html", 0xbfc6c090) = -1 ENOENT (No such file or directory)
[pid 9419] stat64("/home/sridhar/public_html/pg4me/public/sites/default/files/index.htm", 0xbfc6c090) = -1 ENOENT (No such file or directory)
我不知道为什么 NGINX 在 sites/default/files/ 中寻找 index.php 。我检查了模块代码,在 sites/default/files 目录中找不到对索引文件的任何引用。
想知道这种奇怪的行为可能是什么原因造成的