我的nginx服务器支持多个域:
server {
server_name
domain1.com www.domain1.com
domain2.com www.domain2.com
domain3.com www.domain3.com
}
我想为每个域指定不同的重定向规则,例如:
if ( $host ~ "domain1.com" ) {
map $request_uri $redirect_uri {
/about.html /about-us
}
}
if ( $host ~ "domain2.com" ) {
map $request_uri $redirect_uri {
/about.html /contact-us
}
}
nginx只允许if
块中的server
和map
块之外的server
块,所以我卡住了,任何想法如何实现?
也许我应该为每个域包含一个重定向文件,例如:
$redirections_file = "redirections/" . $host;
if ( file_exists( $redirections_file ) ) {
include $redirections_file;
}
这当然不是有效的nginx代码,只是伪代码。