Nginx地图模块301redirect

我在Ruby on Rails中重build了我的网站,现在我想使用Nginx的http://wiki.nginx.org/HttpMapModuleredirect很多旧的URL

出于某种原因,我不能得到它的工作。 它没有改写^ $新的永久物正常工作; 线。

有没有人看到我失踪?

这是我的nginx.conf:

server { server_name example.com; return 301 $scheme://www.example.com$request_uri; } # 301 redirect list map $uri $new { /test123 http://www.example.com/test123; /bla http://www.example.com/bladiebla; } server { server_name www.example.com; rewrite ^ $new permanent; root example/public; location ^~ /assets/ { gzip_static on; expires max; add_header Cache-Control public; } try_files $uri/index.html $uri @unicorn; location @unicorn { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://unicorn-<%= application %>; } error_page 500 502 503 504 /500.html; client_max_body_size 4G; keepalive_timeout 10; } 

这可能是失败的,因为你试图redirect所有的请求,无论它们是否匹配地图中的东西。

为了防止这种情况,请先检查是否有匹配。

 if ($new) { return 301 $new; }