安装Nginx和php见前面的blog
编辑nginx.conf
vi /usr/local/nginx/conf/nginx.conf
#追加index.php让nginx服务器默认支持index.php为首页
location / {
root html;
index index.html index.htm index.php;
}
#然后配置.php请求被传送到后端的php-fpm模块,默认情况下php配置块是被注释的,此时去掉注释并修改为以下内容
#修改fastcgi_param中的/scripts为$document_root
location ~ \.php$ {
root /mnt/phpwww; #指定php的根目录
fastcgi_pass 127.0.0.1:9000; #php-fpm的默认端口是9000
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
配置用户组
#如果php有设置专门的web用户www-data,那么nginx.conf第一行默认是#user nobody; 需要去掉注释改为user www-data;或者user www-data www-data;表示nginx服务器的权限为www-data修改保存并退出,然后重启nginx.
测试index.php
service php-fpm restart
service nginx restart
#编辑index.php
vi /mnt/phpwww/index.php
<?php
phpinfo();
?>
打开浏览器输入对应的地址进行访问,看到输出页面,说明nginx和php都配置好了。
http://192.168.1.1/index.php