原文地址:nginx无法解析php的解决方法
0x00:问题描述
当访问 *.php文件时,没有显示文件的内容而是直接下载了所要访问的文件,如index.php。
0x01:解决方案
::找到nginx的配置文件,修改文件使其支持php
配置文件位置在:/etc/nginx/sites_available/ 下面,如果你没有创建过其他的配置文件,那么应该有一个的默认的名为“default”的配置文件。
1. 打开配置文件,找到文件中的如下内容:
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have “cgi.fix_pathinfo = 0;” in php.ini
# With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
2. 如果你发现上述内容被注释掉了,那么去掉相应的注释。
3. 重启nginx,访问页面。
sudo service nginx restart
4. 如果再次访问出现503错误,请安装php5-fpm后,再次访问
sudo apt-get install php5-fpm