Yaf 在 Nginx 中的配置
Yaf 在 Nginx 下的配置
1、配置样例(Nginx v1.16.1)
server{
listen 80;
server_name 22.local;
root /usr/share/nginx/YfuncT2;
index index.php index.html;
if (!-e $request_filename) {
rewrite ^/(.*) /index.php?$1 last;
}
location / {
if ($request_filename ~* ^.*?.(txt)) {
add_header Content-Disposition "attachment;";
}
try_files $uri $uri/ =404;
}
location ~ .*\.php$ {
include fastcgi.conf;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
}
location ~ /\.ht {
deny all;
}
}
2、错误记录
2.1 File not found.
通过 /var/log/nginx/error.log
中的日志看到的更详细错误是:
2021/01/23 16:31:47 [error] 15368#0: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: t2.local, request: "GET /favicon.ico HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "t2.local"
解决方案
- 检查
fastcgi_param
的参数值
正确的应为 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; - 检查文件权限 (上文对应
/usr/share/nginx/YfuncT2
)
所有者应为nginx
运行用户,并具备执行权限 - 目录路径确认。root 的目录应为项目根目录