nginx 配置增加了try_files后,默认首页就找不到了

nginx 配置增加了try_files $uri $uri.php$is_args$args;一行后,直接访问域名就报错误403 Forbidden,去掉这行才可以,我要保留try_files的配置,请问该如何修改?

server
    {
        listen 80;
        server_name www.aaa.com;
        index index.html index.htm index.php default.html default.htm;
        root  /home/wwwroot/app_htx;

        include none.conf;
        include enable-php.conf;

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /\.
        {
            deny all;
        }

        location / {
                try_files $uri $uri.php$is_args$args;
        }

        access_log  /home/wwwlogs/access.log;
    }

目前估计是去找.php这个文件了,没有找到就报错了,如何修改配置,判断url只有域名或者目录情况就不执行该配置

阅读 6.6k
3 个回答

试试再增加一个location

 location =/ {
                # just keep empty location
 }

配置php的try_files,不能加上$is_args和$args等变量
因为nginx会加上这些字符来查找文件

这些变量应该通过fastcgi的环境变量来传递

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题