文件夹结构如下:
/usr/share/nginx/idevaffiliate/install/templates/bootstrap/css/bootstrap.css
当我试图通过web服务器访问这个和其他静态文件时,我得到403响应:
[30/Aug/2016:04:56:33 +0100] "GET /idevaffiliate/install/templates/bootstrap/css/bootstrap.css HTTP/1.1" 403 46 "http://example.com/idevaffiliate/install/install.php" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36"
这是我的nginx位置指令:
location ~ ^/idevaffiliate/(images|javascript|js|css|flash|media|static)/ {
rewrite ^ https://$server_name$request_uri? permanent;
root /usr/share/nginx/;
expires 30d;
}
location ^~ /idevaffiliate {
root /usr/share/nginx/;
index index.html index.htm index.php;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include /etc/nginx/fastcgi.conf;
}
所有文件和子目录的文件夹权限:
[root@BTCUKSW001 nginx]# ls -la
total 20
drwxr-xr-x 12 nginx nginx 4096 Feb 3 2014 idevaffiliate
节选自/etc/php- fmp .d/www.conf:
[www]
listen = /var/run/php5-fpm.sock
listen.allowed_clients = 127.0.0.1
listen.owner = nginx
listen.group = nginx
listen.mode = 0666
user = nginx
group = nginx
我不知道为什么我有"访问拒绝"的问题。谁能告诉我为什么和如何修复?
你在问题中显示了两个位置块。第一个看起来像一个重定向循环,但永远不会被输入,因为第二个位置块使用^~
修饰符覆盖了它。关于位置块的处理,请参阅本文档。
您收到静态文件403响应的原因是因为您要求php5-fpm
为它们提供服务。fastcgi_pass
指令在你的location ^~ /idevaffiliate
块发送所有的请求到php5-fpm
,当它只想看到PHP脚本。
location ^~ /idevaffiliate {
root /usr/share/nginx;
index index.html index.htm index.php;
...
location ~ '.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include /etc/nginx/fastcgi.conf;
}
}