Ich kämpfe seit zwei Tagen mit meiner Nginx-Konfiguration. Ich habe viel gelesen, konnte aber nicht die richtige Frage finden.
Aus dem Fehlerprotokoll habe ich Folgendes erfahren:
30.08.2018 09:36:29 [Fehler] 1525#1525: *12 FastCGI hat in stderr gesendet: „Primäres Skript unbekannt“ beim Lesen des Antwortheaders vom Upstream, Client: 127.0.0.1, Server: admin.local, Anfrage: „GET / HTTP/1.1“, Upstream: „fastcgi://unix:/run/php/php7.2-fpm.sock:“, Host: „admin.local“
Die Sache ist, gestern konnte ich admin.local in meinem Browser laden. Der einzige Fehler war, dass ich „Datei nicht gefunden“ bekam, wenn ich auf einen Link klickte. (konnte nicht tiefer als /admin.local/ gehen) Jetzt bekomme ich „Datei nicht gefunden“ auf der Zielseite. Ich habe nichts geändert.
mein System: Linux Mint 18 PHP 7.2.9-1+ubuntu16.04.1+deb.sury.org+1 Nginx-Version: nginx/1.14.0
Speicherort meiner index.php:
lrwxrwxrwx 1 www-data www-data 40 Aug 29 13:49 admin -> /home/me/projekte/admin/public/
Mein nginx x-Verzeichnis sieht folgendermaßen aus:
.
├── 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-aktiviert)
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;
}
}
usw./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;
Antwort1
Ich habe meine admin.conf wie folgt aktualisiert:
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;
}
}
das hat mein Problem gelöst.