如何更改nginx网站根目录 以及解析php

nginx默认网站根目录为/usr/local/nginx/html,如果想要将它改成/data/www
需配置 vim /usr/local/nginx/conf/nginx.conf

将其中的字段
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
改为
location ~ .php$ {
root /home/www;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
include fastcgi_params;
}
保存
重启或重新加载nginx服务即可

ps:这里还要说一下就是nginx服务在安装完之后默认位置也是需要配置解析php的,解析方法就是上面未被更改的字段。

原文地址:https://www.cnblogs.com/dantes91/p/5007932.html