NGINX+PHP-FPM7 FastCGI 在 stderr 中发送:“主要脚本未知”

NGINX+PHP-FPM7 FastCGI 在 stderr 中发送:“主要脚本未知”

无法让它工作。我一直在阅读论坛并尝试各种方法。这是在 AWS Linux2 AMI(基于 redhat)上的全新安装,在 /var/www/wordpress 上安装了 wordpress,设置了权限,其中有一个 775 的 phpinfo.php,但无法访问(下面的日志)。我在转到 myhostname、nginx 登陆页面时只得到 http 200。文件也有适当的权限,进程以 nginx 身份运行,尝试更改 listen.mode、vhost conf,但没有任何效果,将继续尝试。任何帮助都将不胜感激,如果缺少文件或设置,请告诉我:

虚拟主机:/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 错误日志:

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;
}

答案1

我通过在CentOS7.3系统中关闭SELINUX解决了这个问题

脚步:

  • 执行setenforce 0

  • 还需要在配置文件中关闭

    vim /etc/selinux/config设置SELINUXdisabled

答案2

解决了:

这是现在的虚拟主机,非常简单(我只需要测试一些东西,它不是产品):

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 处理部分。

相关内容