Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
nginx try_文件未分析php文件_Php_Nginx - Fatal编程技术网

nginx try_文件未分析php文件

nginx try_文件未分析php文件,php,nginx,Php,Nginx,由于历史原因,我的项目被分为三个项目 这使得nginx配置文件非常难以处理,以至于我尝试了许多解决方案,但仍然没有完美地解决它 目录配置: /var/www/html/:项目目录 /mnt/a.com/:另一个项目目录 第三个项目使用反向代理 配置文件如下所示: server { listen 80; listen [::]:80 default ipv6only=on; server_name _; root /var/www/html;

由于历史原因,我的项目被分为三个项目

这使得nginx配置文件非常难以处理,以至于我尝试了许多解决方案,但仍然没有完美地解决它

目录配置:

  • /var/www/html/:项目目录
  • /mnt/a.com/:另一个项目目录
  • 第三个项目使用反向代理
配置文件如下所示:


server {
    listen   80;
    listen   [::]:80 default ipv6only=on;

    server_name _;
    root  /var/www/html;
    index index.html index.htm index.php;

    sendfile off;

    location / {
        try_files $uri $uri/index.html $uri/index.htm $uri/index.php @mnt;
        # try_files $uri $uri/ @mnt;
        # This annotated code causes a 403 error to be returned when accessing an empty directory instead of redirecting to @mnt

    }

    location @mnt {
        root /mnt/a.com;
        try_files $uri $uri/index.html $uri/index.htm $uri/index.php @proxy;
    }

    location @proxy {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://a-proxy.com;
    }


    location ~ \.php$ {
        try_files $uri @mntphp;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param SCRIPT_NAME $fastcgi_script_name;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location @mntphp {
        root /mnt/a.com;
        try_files $uri @proxy;

        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param SCRIPT_NAME $fastcgi_script_name;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    # deny access to . files, for security
    location ~ /\. {
        log_not_found off;
        deny all;
    }

    location ~* \.(jpg|jpeg|gif|png|css|js|ico|webp|tiff|ttf|svg)$ {
        expires 2d;
    }

    error_log   /var/log/a.com_error.log;
    access_log  /var/log/a.com.log;
}
但是这样的配置将导致php文件无法解析。我知道这是因为try_文件将只重定向最后一个参数,但我不知道如何解决这个问题