修改 Nginx 的配置文件
找到如下内容
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
根据注释的说明,加上 index.php 来更好地支持 php
修改后
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html index.php;
接下来找到如下内容
# pass PHP scripts to FastCGI server
#
#location ~ \.php$ {
# include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
# fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
#}
这部分的内容是选择当遇到 php 脚本时应该如何处理
由于刚刚安装的是 php-fpm ,所以去掉部分注释即可
修改后(注意整块内容的完整,不要缺少了大括号)
# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}
也可以选择删除多余内容,只保留如下内容
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
}
修改完毕,重启 Nginx 服务
systemctl restart nginx