我已配置通过 nginx 别名 + php 支持访问本地目录:https://mydomain.de/wbg
指向/var/www/wallabag
。一切工作正常,直到我在服务器上执行正常的 apt-get update && apt-get upgrade(在 debian 8 上运行)。现在,当我打开网站时,我只得到“未指定输入文件。”。以下是 nginx 所说的内容:
2016/02/20 13:07:14 [error] 4376#0: *1 FastCGI sent in stderr: "Unable to open primary script: /var/www/wallabag/index.php/wbg/index.php (No such file or directory)" while reading response header from upstream, client: 78.50.228.24, server: mydomain.de, request: "GET /wbg/ HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "mydomain.de"
这是我的配置的重要部分:
server {
server_name mydomain.de;
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
# ssl configuration
# ...
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
location / {
# ...
}
location /wbg/ {
alias /var/www/wallabag/;
index index.php;
location ~ ^.+?\.php(/.*)?$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename$fastcgi_script_name;
}
}
}
更新后此配置怎么可能失效?我该如何修复它?
(升级后nginx版本为1.6.2-5+deb8u1,php5-fpm:5.6.17+dfsg-0+deb8u1)
答案1
简单的答案是,错误消息与您现在的配置一致 - 所以我不知道更新之前它是如何工作的。
该fastcgi_param SCRIPT_FILENAME $request_filename$fastcgi_script_name
行正在生成一个值,/var/www/wallabag/index.php/wbg/index.php
因为:
$request_filename = /var/www/wallabag/index.php
$fastcgi_script_name = /wbg/index.php
如果你不使用路径信息(即 后面的 URI .php
),你可以简化配置的 PHP 部分并只使用$request_filename
。例如:
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
但是,要从带有路径信息的 URI 构造 SCRIPT_FILENAME,您可以使用:
location ~ \.php(/|$) {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^/wbg(.+\.php)(/.*)?$;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
请注意,为了构造 SCRIPT_FILENAME 的正确值,需要从 URI 中fastcgi_split_path_info
删除前缀。/wbg