Nginx error: FastCGI sent stderr: "main script unknown" while reading response headers from upstream
P粉322319601
P粉322319601 2023-12-15 15:58:59
0
1
518

I have a yii2 premium template application running on centos 9 with nginx and php 8.1. Set up the virtual host configuration as follows:

server {
    lis ten 80;
    server_name mydomain.com;

    root /home/lamtab/xp-app-main/app/appadmin/web;
    index index.php index.html index.htm index.nginx-debian.html;

    access_log "/var/log/nginx/mydomain.com.access.log";
    error_log "/var/log/nginx/mydomain.com.error.log";

    location / {
       try_files $uri /index.php$is_args$args;
    }
   location ~* .php$ {
                # With php-fpm unix sockets
                fastcgi_pass unix:/run/php-fpm/www.sock;
                include         fastcgi_params;
                fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
                fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
        }
    fastcgi_buffers 8 16k;
    fastcgi_buffer_size 32k;
    fastcgi_connect_timeout 90;
    fastcgi_send_timeout 90;
    fastcgi_read_timeout 90;
}

Error log report for domain

FastCGI sends: "main script unknown" in stderr while reading response headers from upstream..."

And nginx error log report

index.php" failed (13: Permission denied)

Any clues?

P粉322319601
P粉322319601

reply all(1)
P粉662089521

In my case, I wasted a few hours in vain and ended up having to just restart the php8.1-fpm service in ubuntu 22.04. It might help to try it. My conf file looks like this

server {
   listen   80 default_server;
   root /home/user/your_project/public/;
   index index.php index.html index.htm;
   access_log /home/user/your_project/nginx-access.log;
   error_log /home/user/your_project/nginx-error.log;
   server_name localhost;

location / {
     try_files $uri $uri/ /index.php$is_args$args;
}

location ~ \.php$ {
    try_files $uri index.php =404;
    fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
   }
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!