配置nginx支持php
vi /usr/local/nginx/conf/nginx.conf #编辑配置文件
user www www; #首行user去掉注释,修改Nginx运行组为www www;必须与/usr/local/php5/etc/php-fpm.conf中的user,group配置相同,否则php运行出错
php-fpm.conf下的用户
index index.php index.html index.htm; #添加index.php
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location / {
root html;
index index.html index.htm;
}
location ~ \.php$ {
root /usr/local/nginx/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;
}
最后检查php和nginx启动的用户是否都为www,如无问题重启服务,web访问测试
php-cgi -b 127.0.0.1:9000 -c /usr/local/php5/etc/php.ini #php配置文件的路径
/etc/init.d/nginx restart #重启nginx
本文转自 转身撞墙角 51CTO博客,原文链接:http://blog.51cto.com/chentianwang/1699587