web-dev-qa-db-ja.com

NGINX + PHP-FPM7 FastCGIがstderrに送信されました: "Primary script unknown"

動作しません。私はフォーラムを読んで、あちこちで試しています。これは、AWS Linux2 AMI(redhatベース)への新規インストールで、wordpress at/var/www/wordpressに設定され、権限を設定し、そこに775のphpinfo.phpがあり、どちらにもアクセスできません。 (以下のログ)myhostname、nginxランディングページにアクセスしているときにhttp 200のみが表示されます。ファイルにも適切な権限があり、プロセスはnginxとして実行され、listen.mode、vhost confを変更してみましたが、何も試行されません。ファイルや設定がない場合はお知らせください:

vhost:/ etc/nginx/sites-available/wp

server {
    listen 80;
    server_name myhostname;
    root /var/www/wordpress/;
    charset utf-8;

    index index.php index.html;

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

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location ~ \.php$ {
        fastcgi_intercept_errors on;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        include fastcgi_params;
    }

    location ~ /\. {
        deny all;
    }

    location ~* /(?:uploads|files)/.*\.php$ {
        deny all;
    }
}

php-fpm:/etc/php-fpm.d/www.conf

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
; RPM: Apache user chosen to provide access to the same directories as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx

; The address on which to accept FastCGI requests.
; Valid syntaxes are:
;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific IPv4 address on
;                            a specific port;
;   '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
;                            a specific port;
;   'port'                 - to listen on a TCP socket to all addresses
;                            (IPv6 and IPv4-mapped) on a specific port;
;   '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = /var/run/php-fpm/php-fpm.sock
;listen = 127.0.0.1:9000
access.log = /var/log/$pool.access.log

; Set listen(2) backlog.
; Default Value: 511
;listen.backlog = 511

; Set permissions for unix socket, if one is used. In Linux, read/write
; permissions must be set in order to allow connections from a web server.
; Default Values: user and group are set as the running user
;                 mode is set to 0660
listen.owner = nginx
listen.group = nginx
listen.mode = 0660

; When POSIX Access Control Lists are supported you can set them using
; these options, value is a comma separated list of user/group names.
; When set, listen.owner and listen.group are ignored
;listen.acl_users = nginx
;listen.acl_groups =

; List of addresses (IPv4/IPv6) of FastCGI clients which are allowed to connect.
; Equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in the original
; PHP FCGI (5.2.2+). Makes sense only with a tcp listening socket. Each address
; must be separated by a comma. If this value is left blank, connections will be
; accepted from any ip address.
; Default Value: any
listen.allowed_clients = 127.0.0.1

nginx error.log:

2018/07/05 17:32:45 [error] 8322#0: *4 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: myPC-IP, server: _, request: "GET /wp-admin/install.php HTTP/1.1", upstream: "fastcgi://unix:/run/php-fpm/php-fpm.sock:", Host: "myhostname"
2018/07/05 17:40:41 [error] 8322#0: *9 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: myPC-IP, server: _, request: "GET /phpinfo.php HTTP/1.1", upstream: "fastcgi://unix:/run/php-fpm/php-fpm.sock:", Host: "myhostname"

/var/log/www.access.log:

- -  05/Jul/2018:17:32:45 +0000 "GET /wp-admin/install.php" 404
- -  05/Jul/2018:17:40:41 +0000 "GET /phpinfo.php" 404

nginx conf.d/php-fpm.conf:

# PHP-FPM FastCGI server
# network or unix domain socket configuration

upstream php-fpm {
        server unix:/run/php-fpm/php-fpm.sock;
}
2
Rancor

解決済み:

これは今のvhostで、超シンプルです(私はいくつかのことをテストする必要があるだけで、それはprodではありません)。

server {
  server_name myec2hostname;
  listen 80;
  root /var/www/wordpress/;
  access_log /var/log/nginx/access.log;
  error_log /var/log/nginx/error.log;
  index index.php;

    location ~ \.php$ {
        root /var/www/wordpress/;
        fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }


    location ~ /\.ht {
      deny  all;
    }
}

Php-fpm.confファイルは同じままでした:ユーザー/グループとしてnginx、unixソケットでリッスン、listen.mode 0660、nginx設定(/ etc/nginx/conf。 d/php-fpm.conf)およびnginx.conf(/ etc/nginx /にある)がvhostファイルの場所を指していない場合は、必ず追加してください。私の場合は、httpブロックに追加しました。 :

include /etc/nginx/sites-enabled/*;

最後に、簡単なvhost confを探して、これを見つけました: http://www.matbra.com/2016/12/07/install-nginx-php-on-Amazon-linux.html どっちPHP処理部分に使用されます。

0
Rancor

CentOS7.3システムでSELINUXを閉じることでこの問題を解決しました

手順:

  • exec setenforce 0
  • 設定ファイルで閉じる必要もあります

    vim /etc/selinux/configSELINUXdisabledに設定

0
kent