【问题标题】:Do I need to install PHP to nginx? PHP files download instead of executing [duplicate]我需要将 PHP 安装到 nginx 吗? PHP文件下载而不是执行[重复]
【发布时间】:2020-05-04 20:32:48
【问题描述】:
在我的网站“craff.ddns.net”上(还没有 24/7 在线)我还没有将 php 安装到 nginx,因为我不确定我是否需要,当我访问我的网站时它只是下载“index.php”。我已经问过一个比我更了解网络服务器的朋友,他说我应该将索引设置为“index.php”,但我已经有了,但它没有用。然后他问我是否安装了php而我没有。如果我没有将php安装到nginx,它会自动开始下载“index.php”吗?我需要安装php还是我需要安装什么?
顺便说一句,我的 nginx 上还没有安装任何东西,我正在 Windows 上运行 nginx。
【问题讨论】:
标签:
php
nginx
indexing
download
execute
【解决方案1】:
Nginx 需要一个程序来处理 php 文件。您需要安装 php-fpm 包。
这是您需要在官方文档中输入服务器块的示例位置。
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
# Mitigate https://httpoxy.org/ vulnerabilities
fastcgi_param HTTP_PROXY "";
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
# include the fastcgi_param setting
include fastcgi_params;
# SCRIPT_FILENAME parameter is used for PHP FPM determining
# the script name. If it is not set in fastcgi_params file,
# i.e. /etc/nginx/fastcgi_params or in the parent contexts,
# please comment off following line:
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}