问下nginx配置问题?

情况是这样的,我nginx配置了这样一段,找不到文件会重定向到index.php

if (!-e $request_filename) {
   rewrite  ^(.*)$  /index.php?s=$1  last;
   break;
}

但是我配置了一些重定向如:

location /device {
          proxy_pass https://test.com/device;
          break;
    }

我原本是想除了device 路径之外的 路径能够走
rewrite ^(.*)$ /index.php?s=$1 last;
但是现在我执行localhost/device 也还是帮我转到 rewrite里面,没有帮我转发?

《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 9

是不是跟顺序有关系

10个月前 评论
donggan (楼主) 10个月前
cccyzloong (作者) 10个月前
donggan (楼主) 10个月前
donggan (楼主) 10个月前

感觉你应该这样写,在原有的配置中新增一个 device

location /device/ {
    alias /sites/device_PATH;
    index index.php;

    if (!-f $request_filename) {
        rewrite  ^(.*)$  /device/index.php?s=$1  last;
    }
}

location ~ ^/device(/.+\.php) {
    alias /sites/device_PATH;

    下列按你实际添加
    fastcgi_pass backend;
    fastcgi_index index.php;
    include fastcgi.conf;
    fastcgi_param SCRIPT_FILENAME $document_root$1;

    fastcgi_split_path_info ^/(.+?\.php)(/.*)$;
    fastcgi_param  PATH_INFO          $fastcgi_path_info;
    fastcgi_param  PATH_TRANSLATED    $document_root$fastcgi_path_info;

}
10个月前 评论

先精确匹配,次之正则,次之最大前缀。 按最大前缀,应走 /device。但不知你的 if (!-e $request_filename) 配置在了哪个 location,如果所在的 location 是正则,且匹配到了,就不会走 /device

10个月前 评论
donggan (楼主) 10个月前
php_yt (作者) 10个月前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!