阿里云centos主机配置nginx
ginx结合php fastcgi完成网页解析,需要进行如下设置:
首先要 配置nginx使用PHP-FPM,修改/etc/nginx/conf.d/default.conf
(1) cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf_bak
说明:为nginx的配置文件作备份
(2)vi /etc/nginx/conf.d/default.conf
在default.conf 文件中,找到以下内容。
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
按i进行编辑,修改为
location / {
root /var/wwwroot;
index index.html index.htm index.php;
}
nginx默认的wwwroot文件夹为/usr/share/nginx/html,这里你可以修改为自己指定的目录,比如我的/var/wwwroot,同时添加 index.php
(3) 配置nginx使用php fastcgi
去除以下内容前的#号,并修改fastcgi_param所在行
#location ~ .php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME [将此处修改为wwwroot路径]$fastcgi_script_name;
# include fastcgi_params;
#}
修改结果
location ~ .php$ {
root wwwroot;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/wwwroot$fastcgi_script_name;
include fastcgi_params;
}
修改完成后,service nginx restart
检验是否修改成功:
在/var/wwwroot下创建phpinfo.php文件: vi /var/wwwroot/phpinfo.php
输入:
phpinfo();
?>
然后按esc 输入 ” :wq” 回车保存
在浏览器键入 你的ip/phpinfo.php如果能出现phpinfo页,说明配置正确了,恭喜恭喜