0

I am struggling for two days with my nginx configuration. I read a lot but could not find the right question.

I got this from the error log:

2018/08/30 09:36:29 [error] 1525#1525: *12 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: admin.local, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.2-fpm.sock:", host: "admin.local"

The thing is, yesterday i was able to load admin.local in my browser. Only fault was i got "File not found." if i klicked a link. (could not go deeper than /admin.local/) Now I got "File not found" on the landing page. I haven't changed anything.

my system: Linux Mint 18 PHP 7.2.9-1+ubuntu16.04.1+deb.sury.org+1 nginx version: nginx/1.14.0

location of my index.php:

lrwxrwxrwx 1 www-data www-data   40 Aug 29 13:49 admin -> /home/me/projekte/admin/public/

My nginx x directory looks like:

.
├── conf.d
│   └── default.conf
├── fastcgi_params
├── koi-utf
├── koi-win
├── mime.types
├── modules -> /usr/lib/nginx/modules
├── nginx.conf
├── scgi_params
├── sites-available
│   └── admin.conf
├── sites-enabled
│   └── admin.conf -> ../sites-available/admin.conf
├── snippets
│   └── fastcgi-php.conf
├── uwsgi_params
└── win-utf

nginx.conf

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*.conf;
}

admin.conf (/sites-enabled)

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

    root /var/www/html/admin;
    index index.php index.html index.htm index.nginx-debian.html;

    server_name admin.local;

    location / {
    try_files $uri $uri/ /index.php$is_args$args;#=404;
    }

    location ~ \.php$ {


        try_files $uri =404;
                fastcgi_read_timeout 864000;
                fastcgi_split_path_info ^(.+\.php)(.*)$;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                #fastcgi_param SERVER_NAME $host;
                fastcgi_param PHP_IDE_CONFIG serverName=$server_name;

        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;
    }

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

etc/hosts

127.0.0.1   admin.local

fastcgi_params

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
fa

stcgi_param  REDIRECT_STATUS    200;
0

I updated my admin.conf to:

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

    root /website/admin/public;
    index index.php;

    server_name admin.local;

    location / {
        try_files $uri $uri/ /index.php$is_args$args;#=404;
    }

    location ~ \.php$ {

                fastcgi_split_path_info ^(.+\.php)(.*)$;
                try_files $uri =404;
                fastcgi_read_timeout 864000;
#               fastcgi_split_path_info ^(.+\.php)(.*)$;
                fastcgi_index index.php;
#               fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#               fastcgi_param SERVER_NAME $host;
#                fastcgi_param PHP_IDE_CONFIG serverName=$server_name;

                include /etc/nginx/fastcgi_params;
                fastcgi_pass unix:/run/php/php7.2-fpm.sock;
    }

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

this solved my problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.