我已经在 Ruby on Rails 中重建了我的网站,现在我想使用 Nginx 的http://wiki.nginx.org/HttpMapModule 301 重定向很多旧的 url
出于某种原因,我无法让它工作。无需重写即可正常工作 ^ $new Permanent; 线。
有没有人看到我错过了什么?
这是我的 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;
}
Run Code Online (Sandbox Code Playgroud)
这可能会失败,因为您正在尝试重定向所有请求,无论它们是否与地图中的某些内容匹配。
为防止出现这种情况,请先检查是否有匹配项。
if ($new) {
return 301 $new;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4803 次 |
最近记录: |