FastCGI は stderr に「メインスクリプトが不明」を送信します。

FastCGI は stderr に「メインスクリプトが不明」を送信します。

aapanelコントロールパネルを使用して、/ blogサブディレクトリにnginxとwordpressを含むnodejsプロジェクトを実行しています。 example.com/blogにアクセスしようとすると、「ファイルが見つかりません」というメッセージが表示されます。間違い。

これはerror.log

2022/11/24 06:59:48 [error] 980362#0: *16041 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: xxx.xxx.xxx.xxx, server: example.com, request: "GET /blog/ HTTP/2.0", upstream: "fastcgi://unix:/tmp/php-cgi-74.sock:", host: "example.com"

これはnodejs nginx設定ファイルです:

server
{
    listen 80;
    listen 443 ssl http2;
    server_name example.com;
    index index.html index.htm default.htm default.html;
    # root /www/wwwroot/example.com;
    
    #SSL-START SSL related configuration
    #error_page 404/404.html;
    #HTTP_TO_HTTPS_START
    if ($server_port !~ 443){
        rewrite ^(/.*)$ https://$host$1 permanent;
    }
    #HTTP_TO_HTTPS_END
    ssl_certificate    /www/server/panel/vhost/cert/example/fullchain.pem;
    ssl_certificate_key    /www/server/panel/vhost/cert/example/privkey.pem;
    ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
    ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
    ssl_prefer_server_ciphers on;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 10m;
    add_header Strict-Transport-Security "max-age=31536000";
    error_page 497  https://$host$request_uri;

    #SSL-END
    
    #ERROR-PAGE-START  Error page related configuration
    #error_page 404 /404.html;
    #error_page 502 /502.html;
    #ERROR-PAGE-END
    
    
    #REWRITE-START Pseudo-static related configuration
    include /www/server/panel/vhost/rewrite/node_example.conf;
    #REWRITE-END
    
    #Files or directories forbidden to access
    location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md|package.json|package-lock.json|\.env|node_modules) {
        return 404;
    }
    
    #One-click application for SSL certificate verification directory related settings
    location /.well-known/ {
        root  /www/wwwroot/example.com;
    }

    # HTTP reverse proxy related settings begin >>>
    location ~ /purge(/.*) {
        proxy_cache_purge cache_one $host$request_uri$is_args$args;
    }

    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header REMOTE-HOST $remote_addr;
        proxy_connect_timeout 30s;
        proxy_read_timeout 86400s;
        proxy_send_timeout 30s;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
    # End of HTTP reverse proxy related settings <<<
    
    location /blog {
        alias /www/wwwroot/example.com/blog;
        index index.php index.html index.htm default.php default.htm default.html;
        try_files $uri $uri/ /index.php?$is_args$args;
        include enable-php.conf;
    }
    
    access_log  /www/wwwlogs/example.log;
    error_log  /www/wwwlogs/example.error.log;
}

この構成ファイルには 2 つのファイルが含まれています。次のようにnode_example.conf空ですenable-php.conf

location ~ [^/]\.php(/|$)
{
    try_files $uri =404;
    fastcgi_pass  unix:/tmp/php-cgi-74.sock;
    fastcgi_index index.php;
    include fastcgi.conf;
}

fastcgi.conf:

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  REQUEST_SCHEME     $scheme;
fastcgi_param  HTTPS              $https if_not_empty;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

文書のphp-fpm.conf内容:

[global]
pid = /www/server/php/74/var/run/php-fpm.pid
error_log = /www/server/php/74/var/log/php-fpm.log
log_level = notice

[www]
listen = /tmp/php-cgi-74.sock
listen.backlog = 8192
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.status_path = /phpfpm_74_status
pm.max_children = 200
pm.start_servers = 15
pm.min_spare_servers = 15
pm.max_spare_servers = 30
request_terminate_timeout = 100
request_slowlog_timeout = 30
slowlog = var/log/slow.log

答え1

nodejsnginx構成ファイルを変更して機能させます。リチャード・スミス彼のコメントについて):

    location /blog {
        root /www/wwwroot/example.com;
        index index.php index.html index.htm default.php default.htm default.html;
        try_files $uri $uri/ /blog/index.php?$is_args$args;
        include enable-php.conf;
    }

関連情報