这在 SO 上出现过几次,但没有一个解决方案有效。这是我目前拥有的:
location / {
try_files $uri $uri/ $uri.php;
}
location @php {
default_type application/x-httpd-php;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param QUERY_STRING $args;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ \.php$ {
#fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param QUERY_STRING $args;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
Run Code Online (Sandbox Code Playgroud)
此示例包含两个选项。首先,编写第一节以通过最终位置节推送 URL/foo.php 和 URL/foo。如果我将第一节$uri.php中的替换为,则它应该使用URL/foo的位置。try_files@php@php
对于@php我尝试设置的位置SCRIPT_FILENAME:
fastcgi_param SCRIPT_FILENAME "/usr/share/nginx/html$uri.php";
fastcgi_param SCRIPT_FILENAME "$request_filename.php";
Run Code Online (Sandbox Code Playgroud)
这些都没有奏效。
在调试这个过程中,没有一add_header行为 URL/foo 发出任何内容。Content-Type 总是设置为 application/octet-stream ,有趣的是,它总是设法发回 php 文件的内容(它被下载)。
我显然做错了什么,但我没有看到什么。