Nginx + php-fpm下载php文件而不执行[重复]

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Nginx + php-fpm下载php文件而不执行[重复]相关的知识,希望对你有一定的参考价值。

这个问题在这里已有答案:

我有nginxphp5.6-fpm,默认端口设置(9000)。我已经通过几个论坛,SO页面和文档来缓解这个问题,但无济于事。

我的网络应用程序的index.php文件应该执行,但所有其他.php文件下载,它似乎与我的重写规则有关,而不是快速流程管理器,但我似乎无法计算。下面是我的site.conf

server {
listen 80 default_server;
listen   [::]:80 ipv6only=on;
server_name xx.xx.xx.xx;
root /var/www/foo.bar.com/html;


# index.php
index index.php index.html;

error_page 404 /404.php;

autoindex off;

location / {
  rewrite ^/(.*)/p/(.*)?$ /product.php?slug=$2 break;
  rewrite ^/?([A-Za-z0-9_-]+)/?$ /vendor.php?vendor=$1 break;

  if (!-e $request_filename){
  rewrite ^(.*)$ /$1.php break;
  } 

 }

 location /cart {
   rewrite ^/cart/?$ /cart.php break;
 }

 location /checkout {
   rewrite ^/checkout/?$ /checkout.php break;
 }

 location /search/ {
   rewrite ^/search/?$ /search.php break;
   rewrite ^/search/(.*)?$ /search.php?slug=$1 break;
   rewrite ^/search/brand/(.*)?$ /search.php?brandslug=$2 break;
 }

 location /brand {
  rewrite ^/brand/(.*)?$ /search.php?brand=$1 break;
 }

  location /brands {
   rewrite ^/brands/?$ /productbrands.php break;
  }

  location /404 {
    rewrite ^/404/?$ /404.php break;
  }

  location /vendors {
   rewrite ^/vendors/?$ /vendors.php break;
 }
   include  /etc/nginx/mime.types;

    # handle .php
    location ~* .php(/|$) {
      try_files      $uri =404;
      include  /etc/nginx/mime.types;
      fastcgi_pass   127.0.0.1:9000;
      fastcgi_index index.php;
      fastcgi_split_path_info ^(.+.php)(/.*)$;
      include fastcgi_params;
      fastcgi_param  SCRIPT_FILENAME     $request_filename;
      fastcgi_param  HTTPS              off;
      include nginxconfig.io/php_fastcgi.conf;

}

  location ~ /. {
     access_log off;
     log_not_found off; 
     deny all;
  }
  location ~* .(jpg|jpeg|gif|png|css|js|ico|xml)$ {
     include  /etc/nginx/mime.types;
     access_log        off;
     log_not_found     off;
     expires           360d;
   }

     include nginxconfig.io/general.conf;
 }
答案

请添加:

location ~ .php$ {
    fastcgi_split_path_info ^(.+.php)(/.+)$;
    include fastcgi.conf;
    fastcgi_intercept_errors on;
    fastcgi_pass unix:/run/php/php5.6-fpm.sock;
}

以上是关于Nginx + php-fpm下载php文件而不执行[重复]的主要内容,如果未能解决你的问题,请参考以下文章

nginx/php-fpm 访问php文件直接下载而不运行

如果正在进行流式下载,Nginx PHP-FPM无法提供请求

docker创建nginx+php-fpm环境

Docker - Nginx + Php-fpm 开发环境

使用 Nginx + PHP-FPM 拒绝访问 PHP 文件 (403)

nginx+php-fpm 问题无法调用文件夹中的其他 php 文件