加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

linux – 如果使用NGINX找不到文件,如何重写

发布时间:2020-12-13 21:21:09 所属栏目:Nginx 来源:网络整理
导读:我在Ubuntu服务器上使用NGINX.我有这个vhost: 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_FILENA

我在Ubuntu服务器上使用NGINX.我有这个vhost:

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.

另请参阅nginx wiki上的front controller部分.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读