我为我的 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;
}
}
这解决了我的问题。