我正在将一个旧网站移到一个新的基于nginx的主机上。 为了保存URL(完全改变),我有一个文件列出了映射。 我想用它与地图模块 。
里面的/etc/nginx/nginx.conf http{ ... }我指的是PERL和小写函数:
#Include PERL and have a function for lowercasing the incoming URL perl_modules perl/lib; # function to lowercase incoming strings like the URL perl_set $uri_lowercase 'sub { my $r = shift; my $uri = $r->uri; $uri = lc($uri); return $uri; }';
我的站点configuration文件在/etc/nginx/sites-enabled/notessensei (Thx Alexey指出)如下所示:
server { listen www.notessensei.com:80; root /home/stw/www; index index.html; server_name www.notessensei.com notessensei.com; location / { map $uri_lowercase $new { include /home/stw/www/blognginx.map; } if ($new) { rewrite ^ $new redirect; } } error_page 404 /blog/404.html; }
映射文件blognginx.map如下所示:
/blog/d6plinks/shwl-6bv35s /blog/2005/04/garbage-in-.html; /blog/d6plinks/shwl-6c6ggp /blog/2005/05/just-me.html; /blog/d6plinks/shwl-6c6gh4 /blog/2005/05/it-is-quotmake-your-own-caption-quot-time.html; /blog/d6plinks/shwl-6c997j /blog/2005/05/big-business-wwjd.html; /blog/d6plinks/shwl-6ca5qb /blog/2005/05/domino-on-solaris-anyone.html; /blog/d6plinks/shwl-6ce65j /blog/2005/05/going-places-vietnam.html; /blog/d6plinks/shwl-6ce6c9 /blog/2006/02/umsys-as-old-as-unix-sort-of.html;
约1300线。 当我做一个service nginx configtest我得到一个失败 。 当我不使用include语句时,我得到一个OK。 现在我有两个问题:
非常感谢帮助。
map指令必须是直接子http块。
语法:mapstring$variables{…}
默认: –
上下文:http
在你的情况下,你必须把它放在server块旁边,因为你自定义的configuration文件包含在nginx.conf中的http块中。
map $uri_lowercase $new { include /home/stw/www/blognginx.map; } server { ... }
我明白了,这是阿列克谢的指针。 有一个4倍的问题:
service nginx configtest告诉不到nginx -t ,Alexey又指了指那里 现在我的/etc/nginx/nginx.conf在http {}部分增加了两行:
## Increase bucket for big redirects map_hash_bucket_size 256; map_hash_max_size 4092;
和/etc/nginx/sites-enabled/notessensei文件如下所示:
map $uri_lowercase $new { include /home/stw/www/blognginx.map; } server { listen www.notessensei.com:80; root /home/stw/www; index index.html index.htm; server_name www.notessensei.com notessensei.com; location / { if ($new) { return 301 $new; } } error_page 404 /blog/404.html; }
如果你想看到它的行动,从wissel.net挑选任何博客条目, 并将 uri部分应用到notessensei.com – 像1200条目的魅力。