- 背景介绍
默认安装的Nginx是无法打开php文件的,需要修改相关配置才能支持php - 安装
yum -y install epel-release
yum -y install nginx
yum install php php-mysql php-fpm
vi /etc/php.ini
修改cgi.fix_pathinfo=0
sed -i "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g" /etc/php.ini
vi /etc/php-fpm.d/www.conf
追加一条Listen参数:
listen = /var/run/php-fpm/php-fpm.sock
service php-fpm restart
chkconfig php-fpm on - 修改Nginx虚拟主机文件,使其支持php
location ~ .php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
重启nginx服务
service nginx restart