Resolving error "Primary script unknown" with Nginx

1

When configuring a LEMP (Nginx, MySQL, FPM) on Ubuntu 16.04, version 7 of PHP and FPM and when I went to do a test with php, the nginx log throws this at me.

  

2016/08/08 22:54:50 [error] 2251 # 2251: * 4 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: fanut.localhost , request: "GET / HTTP / 1.1", upstream: "fastcgi: //127.0.0.1: 9000", host: "fanut.localhost"

I leave the configuration of my virtual Host because I read that it is from the fastcgi script but I can not find what is happening to it. Thanks in advance.

server {
listen 80 default_server;
listen [::]:80 default_server;

root /home/user/html/proyecto/public;

# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;

server_name proyecto.localhost www.proyecto.localhost;

location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to displaying a 404.
    try_files $uri $uri/ =404;
}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
            include snippets/fastcgi-php.conf;

    #       # With php7.0-cgi alone:
            fastcgi_pass 127.0.0.1:9000;
            include fastcgi_params;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    #       # With php7.0-fpm:
    #       fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }


# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
location ~ /\.ht {
    deny all;
}

}

    
asked by davidplpz 08.08.2016 в 23:15
source

1 answer

0

I leave the configuration that works for me in my local and servers:

location ~ \.php($|/) {
    include fastcgi_params;

    fastcgi_pass unix:/tmp/php-fpm.sock;

    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param HTTPS off;

    # fastcgi_index  local_index.php;
}

with fastcgi_split_path_info ^(.+\.php)(/.+)$; you indicate how the route being used should be divided.

and with fastcgi_param PATH_INFO $fastcgi_path_info; you pass the parameter to php-fpm

    
answered by 09.08.2016 / 12:51
source