多网站情况下配置nginx 301 永久重定向
- 时间:
- 来源:开源中国
已经配置成功2个网站在lnmp环境下
修改其中一个网站的301重定向
Step 1:
虚拟主机配置文件 xxx.com.conf修改成:
server_name xxx.com;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/xxx.com;
再server段外面增加另一个server段:
server {
server_name www.xxx.com;
rewrite ^(.*) http://xxx.com$1 permanent;
}
保存,退出,nginx -t检查,nginx -s reload重启。
百度 301检查,输入网址 www.xxx.com ,提示 301重定向。
Note:无需.htaccess文件。此文件只有在有apache中才有效果。没有apache,配置了,不生效的。