php - nginx 下载 php 文件而不是执行它们
问题描述
我正在尝试设置一个 LEMP 堆栈,经过几个教程后,我似乎无法让 php 在这里工作,这是我的 nginx 配置:
默认配置:
server {
listen 80 0.0.0.0;
listen [::]:80 0.0.0.0 ipv6only=on;
# note that these lines are originally from the "location /" block
root /usr/share/nginx/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
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;
}
}
解决方案
我相信您的问题是try_files
PHP 块内部的第二次使用:
location ~ \.php$ {
===>try_files $uri =404;<====
fastcgi_split_path_info ^(.+\.php)(/.+)$;
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;
}
把那条线拿出来试试这个:
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
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;
}
推荐阅读
- javascript - chrome 83 中未定义所需的道具
- listview - Xamarin.Forms - ListView 加载/填充后如何滚动到底部?
- amazon-web-services - 使用 gitlab CI 通过 CLI 创建 lambda 函数时出错(解析参数“--zip-file”时出错:无法加载参数文件)
- wordpress - 如何在 WooCommerce REST API(related_ids) 中获取相关产品?
- cypress - “.to.be.sorted()”断言不适用于赛普拉斯
- android - Android可点击跨度点击激活所有TextView不仅可跨文本
- assembly - 在制作 PIE 对象时,不能使用针对未定义符号“ELF”的重定位 R_X86_64_8
- docker - 如何修复 minikube - skaffold 本地环境的服务端口?
- java - QueryDSL 为子查询重用表别名
- python - 如何使用python在opencv中加载图像?