需求:实现当 www.aa.com域名进来时,跳转到www.bb.com域名进行访问
1.实现301域名跳转
server
{
listen 80;
server_name www.bb.com www.aa.com;
if ($host != ‘www.bb.com’)
{
rewrite ^/(.*)$ http://www.bb.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.bb.com www.aa.com;
if ($host != ‘www.bb.com’)
{
rewrite ^/(.*)$ http://www.bb.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重新载入配置文件
评论 (0)