今天一个网友叫我帮他在我的vps上配置nginx虚拟机时,发现我更改虚拟机的根路径后,nginx只会执行,nginx默认的配置的根目录下的index.php,但是index.html的,却可以执行,觉得怪怪的,一时找不到方向怎么搞了,只好查看官方文档,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | 现在我们来看在一个典型的,简单的PHP站点中,nginx怎样为一个请求选择location来处理:
server {
listen 80;
server_name example.org www.example.org;
root
/data/www
;
location / {
index index.html index.php;
}
location ~* \.(gif|jpg|png)$ {
expires 30d;
}
location ~ \.php$ {
fastcgi_pass localhost:9000;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
include fastcgi_params;
}
}
|
这是官方的文档,而我的错误就使用location 匹配php文件的那个位置的根目录没有更改过来,导致找不到文件,file not found
以后配置需要注意一下一点:
1:把root 写在server下,不要写在location下,
2:把location下的root 删除