微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

url-rewriting – nginx重写规则

我正在尝试为以下情况实现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"

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐