在nginx中重写不起作用

在nginx中重写不起作用,nginx,Nginx,我正在windows10中使用Nginx1.8.0,这是我试图重写请求的核心配置 server { listen 80; server_name localhost; rewrite ^/qt/(\w+)/(\d+)/(\d+)/(\d+)_(\d+).(\w+)$ /qtfile/$1/$4/$5.$6 last; # /qt/zoom/x_plus/y_plus/x_y.type ==> /qtfile/zoom/x/y.type

我正在windows10中使用Nginx1.8.0,这是我试图重写请求的核心配置

server {
    listen       80;
    server_name  localhost;
    rewrite ^/qt/(\w+)/(\d+)/(\d+)/(\d+)_(\d+).(\w+)$ /qtfile/$1/$4/$5.$6 last;
    # /qt/zoom/x_plus/y_plus/x_y.type   ==>  /qtfile/zoom/x/y.type


    location /qtfile {
        access_log logs/images.log;
        alias   D:/tiles/;
    }
    location / {
        root   D:/www;
    }
}
链接
http://localhost/qtfile/s/214/7645/102.jpg
将返回正确的图像,但是链接
http://localhost/qt/s/214/323/34254/7645_102.jpg
将抛出错误:

2015/10/10 10:40:09 [error] 1420#11676: *1 CreateFile() "D:/www/qt/s/214/323/34254/7645_102.jpg" failed (3: The system cannot find the path specified), client: 127.0.0.1, server: localhost, request: "GET /qt/s/214/323/34254/7645_102.jpg HTTP/1.1", host: "localhost"
请求似乎被
loation/
段捕获


有什么问题吗?

看起来您的正则表达式输入不正确。您给出了示例
http://localhost/qt/s/214/323/34254/7645_102.jpg
使用正则表达式
^/qt/(\w+)/(\d+)/(\d+)/(\d+)/(\d+)。(\w+)$
。您的正则表达式中只有两个数字段,但URL中有三个

根据URL,您的正则表达式应为:

^/qt/(\w+)/\d+/\d+/\d+/(\d+)_(\d+).(\w+)$
您必须将重写的第二部分调整为

/qtfile/$1/$2/$3.$4