Назад | Перейти на главную страницу

NGINX + PHP-FPM7 FastCGI, отправленный в stderr: «Основной сценарий неизвестен»

Не могу заставить это работать. Я читал форумы и пробовал тут и там. Это новая установка на AWS Linux2 AMI (на основе redhat), установленный wordpress в / var / www / wordpress, установлены разрешения, есть phpinfo.php с 775 там, который не может получить доступ ни к одному из них (журналы ниже). Я получаю http 200 только при переходе на myhostname, целевую страницу nginx. Файлы также имеют надлежащие разрешения, процесс работает как nginx, пытался изменить listen.mode, vhost conf, но ничего, будет продолжать попытки. Любая помощь будет принята с благодарностью, дайте мне знать, если файл или настройки отсутствуют:

виртуальный хост: / и т.д. / Nginx / сайты-доступные / 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;
}

Я решил эту проблему, закрыв SELINUX в ​​системе CentOS7.3

шаги:

  • exec setenforce 0

  • также необходимо закрыть в файле конфигурации

    vim /etc/selinux/config устанавливать SELINUX к disabled

Решено:

Теперь это vhost, супер простой (мне просто нужно кое-что протестировать, это не продукт):

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.