首页 > 其他 > 详细

nginx设置301跳转

时间:2015-05-26 16:27:21      阅读:193      评论:0      收藏:0      [点我收藏+]

在server段域名下设置:

if ( $host = ‘xxxx.com‘ ) {        
     rewrite ^/(.*)$ http://www.xxxx.com/$1 permanent; 
}

permanent – 返回永久重定向的HTTP状态301

这里要注意的是,nginx语法检测特别严格,if和后面括号以及变量等号这些元素都要有空格。

如果没有空格的话会报[emerg] unknown directive “if($host!=”这样的错误。


检查配置是否正确

/usr/local/nginx/sbin/nginx -t

提示:

the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
configuration file /usr/local/nginx/conf/nginx.conf test is successful

说明配置文件无错误

/usr/local/nginx/sbin/nginx -s reload

重启nginx即可。

nginx设置301跳转

原文:http://xtceetg.blog.51cto.com/5086648/1655192

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!