修改root根目录配置
注:
什么都不修改的情况下,服务器默认显示的是html目录下的 index.html 首页内容
![]()
因为 没修改配置文件之前 是这样的:
![]()
但是 在实际项目开发中,很多都不是默认目录,所以就要手动配置修改了
以下只稍微分了两种情况:
A)在html目录下继续新建文件(如:myApp),里面放的就是你的项目代码文件
此时将其中的
location / {
root
html;
index
index.php index.html index.htm;
}
改为
location / {
root
html/myApp;
index
index.php index.html index.htm;
}
然后再将
location ~ \.php$ {
root
html;
fastcgi_pass
127.0.0.1:9000;
fastcgi_index
index.php;
fastcgi_param
SCRIPT_FILENAME
$document_root$fastcgi_script_name;
include
fastcgi_params;
}
改为
location ~ \.php$ {
root
html/myApp;
fastcgi_pass
127.0.0.1:9000;
fastcgi_index
index.php;
fastcgi_param
SCRIPT_FILENAME
$document_root$fastcgi_script_name;
include
fastcgi_params;
}
然后 别忘了重启然后重启nginx 就可以访问到你重新配置的项目首页了!
![]()
B)第二种情况,其实原理是一样,改的地方也是一样的。
这种情况,不在html目录下新建文件夹,要访问其他盘下的项目文件也是可以的
比如此时,nginx此时安装在f盘,但是我要把默认首页改到d盘的myApp目录下的首页,其修改配置文件如下:
(其实是一样的和第一种情况,就再啰嗦一点吧)
此时将其中的
location / {
root
html;
index
index.php index.html index.htm;
}
改为
location / {
root
d:/myApp;
index
index.php index.html index.htm;
}
然后再将
location ~ \.php$ {
root
html;
fastcgi_pass
127.0.0.1:9000;
fastcgi_index
index.php;
fastcgi_param
SCRIPT_FILENAME
$document_root$fastcgi_script_name;
include
fastcgi_params;
}
改为
location ~ \.php$ {
root
d:/myApp;
fastcgi_pass
127.0.0.1:9000;
fastcgi_index
index.php;
fastcgi_param
SCRIPT_FILENAME
$document_root$fastcgi_script_name;
include
fastcgi_params;
}
然后,还是重启你的nginx,就可以看到你配置的首页了:
![]()
批注:1.10.3及以上版本的nginx location ~ \.php$中的配置是注释掉了,是不需要配置的