Url rewriting nginx重写规则

Url rewriting nginx重写规则,url-rewriting,nginx,Url Rewriting,Nginx,我正在尝试为以下情况实施nginx重写规则: -请求/testfa/styles/style.css应重定向到/testfa/templates/styles/style.css 我已经为我的服务器启用了重写日志记录,并创建了以下规则: location /testfa { rewrite ^/styles/(.+)?$ /testfa/templates/styles/$1 last; } 但当我尝试执行请求时,我从服务器收到404错误,并且日志文件不包含任何关于重写的信息,只

我正在尝试为以下情况实施
nginx
重写规则: -请求
/testfa/styles/style.css
应重定向到
/testfa/templates/styles/style.css
我已经为我的服务器启用了重写日志记录,并创建了以下规则:

location /testfa {     
  rewrite ^/styles/(.+)?$ /testfa/templates/styles/$1 last;
}
但当我尝试执行请求时,我从服务器收到404错误,并且日志文件不包含任何关于重写的信息,只包含以下消息:

open() "......../testfa/styles/style.css" failed (2: No such file or directory)
nginx
执行这种重写的正确方法是什么

location /testfa/ {
    rewrite ^/testfa/styles/(.+)$ /testfa/templates/styles/$1 last;
}
这对你有用吗

我的测试虚拟>

server {
    listen          ...ip...:80;
    server_name     sub.domain.com;
    root            /usr/local/www/test;
    error_log       /usr/local/www/test/error_debug.log debug;

    rewrite_log     on;

    location /testfa/ {
        rewrite ^/testfa/styles/(.+)$ /testfa/templates/styles/$1 last;
    }
}
这很有效。甚至日志也报告:

2011/11/25 01:06:52 [notice] 35208#0: *456705 rewritten data: "/testfa/templates/styles/test.css", args: "", client: IP, server: sub.domain.com, request: "GET /testfa/styles/test.css HTTP/1.1", host: "sub.domain.com"

不,仍然没有运气-日志中同样的“没有这样的文件或目录”,日志中没有重写信息。我在自己的nginx服务器上尝试了它,它工作正常。可以粘贴所有虚拟主机规则吗?主配置:
server{listen 80;index index.php index.html;server_name dev.example.com;root/var/www/www.example.com/www_dev;error_log/var/log/nginx/www.example.com.dev.log调试;重写_登录;包含conf.d/dev_rules.inc;}
Include file:
location/testfa/{rewrite^/testfa/styles/(.+)$/testfa/templates/styles/$1 last;}
你能试试Include文件的绝对路径吗?我已经更新了上面的答案,更好的预览。它工作正常,在我的nginx 1.0.8上进行了测试