NGINX正在下载php文件,但当我使用https时文件会执行

NGINX正在下载php文件,但当我使用https时文件会执行,php,nginx,ssl-certificate,Php,Nginx,Ssl Certificate,当我使用https时,服务器上的php文件执行良好:// 但当我在浏览器中使用http://时,它开始下载.php文件作为代码。 我已经在服务器上安装了lets加密ssl 这是我的/etc/nginx/conf.d/default.conf文件 服务器{ 服务器名称localhost; root/usr/share/nginx/html; index.php index.html index.htm; 地点/{ try_files$uri$uri/=404; } 错误\u第404/404.ht

当我使用https时,服务器上的php文件执行良好:// 但当我在浏览器中使用http://时,它开始下载.php文件作为代码。 我已经在服务器上安装了lets加密ssl

这是我的/etc/nginx/conf.d/default.conf文件

服务器{
服务器名称localhost;
root/usr/share/nginx/html;
index.php index.html index.htm;
地点/{
try_files$uri$uri/=404;
}
错误\u第404/404.html页;
错误\u第500页502 503 504/50x.html;
location=/50x.html{
root/usr/share/nginx/html;
}
位置~\.php${
fastcgi\u split\u path\u info^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index.php;
包括fastcgi.conf;
}
侦听443 ssl;#由Certbot管理
ssl_certificate/etc/letsencrypt/live/localhost/fullchain.pem;#由Certbot管理
ssl_certificate_key/etc/letsencrypt/live/localhost/privkey.pem;#由Certbot管理
include/etc/letsencrypt/options-ssl-nginx.conf;#由Certbot管理
ssl_dhparam/etc/letsencrypt/ssl-dhparams.pem;#由Certbot管理
}
服务器{
如果($host=localhost){
返回301 https://$host$request\u uri;
}#由Certbot管理
如果($host=localhost){
返回301 https://$host$request\u uri;
}#由Certbot管理
听80;
服务器名称localhost;
返回404;#由Certbot管理
}
服务器{
如果($host=localhost){
返回301 https://$host$request\u uri;
}#由Certbot管理
如果($host=localhost){
返回301 https://$host$request\u uri;
}#由Certbot管理
听80;
服务器名称localhost;
返回404;#由Certbot管理

}
HTTP是端口80,HTTPS是端口443。你需要有

listen 80;
在告诉nginx将请求传递给PHP的服务器块中。下面的配置在您的服务器块中,带有
listen443
,这就是HTTPS执行php文件而不是下载它的原因

 location ~ \.php$ {
  fastcgi_split_path_info ^(.+\.php)(/.+)$;
  fastcgi_pass 127.0.0.1:9000;
  fastcgi_index index.php;
  include fastcgi.conf;
 }

没有有效的解决方案,所以我强制将所有http://traffic重定向到https://

location~\.php${fastcgi\u split\u path\u info^(.+\.php)(/.+)$;fastcgi\u pass 127.0.0.1:9000;fastcgi\u index.php;include fastcgi.conf;}我添加了这段代码来监听80;块仍然没有执行php文件。您还有两个服务器块正在侦听端口80。你只需要1你的配置几乎无法读取,因为它凌乱不堪,你怎么能产生如此糟糕的代码?这就是当你盲目复制粘贴而不了解自己在做什么时会发生的情况。建议的解决方案是有效的,因为它不是复制粘贴,所以您无法应用该解决方案。