Nginx 403禁止在PHP文件上使用Location指令
这是我的服务器块:Nginx 403禁止在PHP文件上使用Location指令,php,nginx,Php,Nginx,这是我的服务器块: server { listen 80; server_name localhost; root /www/html; index index.php; location = / { autoindex on; index index.php; try_files $uri $uri/ =404; } location ~*\.(css|js|gif|jp
server {
listen 80;
server_name localhost;
root /www/html;
index index.php;
location = / {
autoindex on;
index index.php;
try_files $uri $uri/ =404;
}
location ~*\.(css|js|gif|jpe?g|png)$ {
root /www/html/shared;
rewrite ^/releases(.*)$ $1 last;
expires 5m;
}
location ~* \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
现在,当我试图访问“localhost/”时,这样做只会抛出一个“403禁止”错误。但是,如果我直接访问该页面--“localhost/index.php”,则该页面工作得非常好。我一辈子都不知道为什么。error.log也没有给我任何有用的信息或错误代码——只是页面被“禁止”。
下面是抛出的错误:
2017/03/29 14:37:35 [error] 11980#8840: *94 directory index of "C:/www/html/" is forbidden, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", host: "localhost"
这是一个基于windows的nginx服务器。这个答案让人失望,但我会回答这个问题,如果有人遇到这个愚蠢的问题,他们可以解决 php正在查找前缀为“/www/html”,而不是“/www/html/”的文件,因此当它想要我的索引时,它试图加载“/www/htmlindex.php”,而不是“/www/html/index.php” 您可以通过执行以下任一操作来解决此问题:
fastcgi_index /index.php;
或者在根的末尾添加一个/。这个答案有点令人失望,但我会回答这个问题,如果有人遇到这个愚蠢的问题,他们可以解决它 php正在查找前缀为“/www/html”,而不是“/www/html/”的文件,因此当它想要我的索引时,它试图加载“/www/htmlindex.php”,而不是“/www/html/index.php” 您可以通过执行以下任一操作来解决此问题:
fastcgi_index /index.php;
或者将/添加到根的末尾。尝试:
location/{…}
而不使用=
。另外,删除上的autoindex
。尝试一下,但似乎没有改变输出。请尝试:location/{…}
而不使用=
。另外,删除上的autoindex
。尝试了一下,但似乎没有改变输出。