【问题标题】:Nginx + php-fpm downloading php file and not executing [duplicate]Nginx + php-fpm下载php文件而不执行[重复]
【发布时间】:2019-08-09 20:56:10
【问题描述】:

我在默认端口 (9000) 上设置了 nginxphp5.6-fpm。 我已经浏览了几个论坛、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;
 }

【问题讨论】:

    标签: php nginx


    【解决方案1】:

    请添加:

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

    【讨论】:

    • 对我不起作用,仍然只执行索引页面,下载任何其他链接的 PHP 页面。
    • 我已经在链接的问题页面上写了我的解决方案,我的是一个重写规则问题,显然这也可能导致 nginx 下载文件而不是将其发送到 fcgi @Bhupendra Dudhwal
    猜你喜欢
    • 2017-06-05
    • 1970-01-01
    • 1970-01-01
    • 2019-07-21
    • 2011-12-30
    • 1970-01-01
    • 2016-03-18
    • 1970-01-01
    • 2014-10-17
    相关资源
    最近更新 更多