码迷,mamicode.com
首页 > 系统相关 > 详细

Linux10.5 Nginx域名重定向

时间:2018-05-16 20:42:14      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:permanent   div   server   conf   lin   moved   default   title   local   

更改test.com.conf
server
{
    listen 80;
    server_name test.com test1.com test2.com;
    index index.html index.htm index.php;
    root /data/wwwroot/test.com;
    if ($host != ‘test.com‘ ) 
    {
        rewrite  http://$host/(.*)$  http://test.com/$1  permanent;
    }
}
// $1就是(.*)括号内的

[root@localhost ~]# curl -x127.0.0.1:80 test2.com/index.html
<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.12.1</center>
</body>
</html>
[root@localhost ~]# curl -x127.0.0.1:80 qq.com/index.html
echo “This is a default site.”
[root@localhost ~]# curl -x127.0.0.1:80 test1.com/index.html
<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.12.1</center>
</body>
</html>

  

Linux10.5 Nginx域名重定向

标签:permanent   div   server   conf   lin   moved   default   title   local   

原文地址:https://www.cnblogs.com/chyuanliu/p/9047753.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!