1>实现301域名跳转
server
{
listen 80;
server_name www.aa.com www.bb.com;
if ($host != \'www.aa.com\')
{
rewrite ^/(.*)$ http://www.aa.com/$1 permanent;
}
index index.html index.htm index.php;
root /usr/local/nginx/html;
}
2>实现302跳转premanent 改为redirect
server
{
listen 80;
server_name www.aa.com www.bb.com;
if ($host != \'www.aa.com\')
{
rewrite ^/(.*)$ http://www.aa.com/$1 redirect;
}
index index.html index.htm index.php;
root /usr/local/nginx/html;
}
3>检查错误和重启服务
检查是否有错:/usr/local/nginx/sbin/nginx -t
重启服务 : service nginx restart
或者
/etc/init.d/nginx reload重新载入配置文件