今天一个网友叫我帮他在个人vps上配置nginx虚拟机时,发现我更改虚拟机的根路径后,nginx只会执行,nginx默认的配置的根目录下的index.php,可是index.html的,却能够执行,以为怪怪的,一时找不到方向怎么搞了,只好查看官方文档,php
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 foundhtml
之后配置须要注意一下一点:nginx
1:把root 写在server下,不要写在location下,spa
2:把location下的root 删除code