![了解 Nginx try_files 和 fastcgi_path](https://linux22.com/image/798449/%E4%BA%86%E8%A7%A3%20Nginx%20try_files%20%E5%92%8C%20fastcgi_path.png)
我正在尝试将一个非常简单的 .htaccess 文件转换为 nginx:
Options -Indexes -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
我在 Google 和很多地方都看到,try_files 应该可以解决问题。我尝试了很多方法,但就是不起作用,看起来什么都没有发送到 index.php
server {
root /var/www/html/;
location / {
index index.php;
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
文件结构很简单:
/var/www/html/folder1/folder2/index.php
/var/www/html/folder1/folder2/.htaccess
请求url时Nginx错误日志:
013/01/17 14:38:28 [error] 22379#0: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 1.2.3.4, server: , request: "GET /status/1.0/APP/ HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "test.com:443"
我不确定问题是 try_files 问题还是 fastcgi_path。
谢谢你,