繁体   English   中英

Nginx重写规则

[英]nginx rewrite rules

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM