2017年5月17日

nginx 多網址重定向設定

把 aaa.com bbb.com ccc.com 重定向成 www.aaa.com www.bbb.com www.ccc.com,設定如下

server {
listen 80;
server_name aaa.com bbb.com ccc.com;

return 301 http://www.$host$request_uri;
}

server {
listen 80;
server_name www.aaa.com;
}

server {
listen 80;
server_name www.bbb.com;
}

server {
listen 80;
server_name www.ccc.com;
}


重點在
return 301 http://www.$host$request_uri;

$host
in this order of precedence: host name from the request line, or host name from the 「 Host 」 request header field, or the server name matching a request
$http_name
arbitrary request header field; the last part of a variable name is the field name converted to lower case with dashes replaced by underscores
$server_name
name of the server which accepted a request

0 意見:

張貼留言