我在 nginx 配置上苦苦掙扎了兩天。我讀了很多但找不到正確的問題。
我從錯誤日誌中得到了這個:
2018/08/30 09:36:29 [錯誤] 1525#1525: *12 FastCGI 在stderr 中發送:“主腳本未知”,同時從上游讀取響應頭,客戶端:127.0.0.1,伺服器:admin. local,請求: “GET / HTTP/1.1”,上游:“fastcgi://unix:/run/php/php7.2-fpm.sock:”,主機:“admin.local”
問題是,昨天我能夠在瀏覽器中載入 admin.local。唯一的錯誤是我收到“找不到文件”。如果我點擊一個連結。 (無法比 /admin.local/ 更深入)現在我在登陸頁面上看到“找不到文件”。我沒有改變任何東西。
我的系統:Linux Mint 18 PHP 7.2.9-1+ubuntu16.04.1+deb.sury.org+1 nginx版本:nginx/1.14.0
我的index.php 的位置:
lrwxrwxrwx 1 www-data www-data 40 Aug 29 13:49 admin -> /home/me/projekte/admin/public/
我的 nginx x 目錄如下所示:
.
├── 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;
}
}
等/主機
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;
答案1
我將 admin.conf 更新為:
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;
}
}
這解決了我的問題。