我在 Ubuntu 服务器上使用 NGINX。我有这个虚拟主机:
server {
listen 80;
server_name *.example.com;
root /home/nginx/vhosts/example.com/web;
location / {
index index.php;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9001;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
}
我必须添加一条规则...
如果找不到文件/目录,请使用 index.php
如何更改我的服务器 {} 指令?
谢谢!
最佳答案
您可以使用 try_files 指令:
try_files $uri $uri/ /index.php
这将首先尝试查找文件和目录,如果这不起作用,它将使用 index.php。
另见 front controller nginx wiki 上的部分。
关于linux - 如果使用 NGINX 找不到文件,如何重写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5920081/