12、8 nginx域名重定向

Nginx的域名重定向与httpd类似。
vim /usr/local/nginx/conf/vhost/moved.conf
 
server
{
    listen 80;
    #nginx可以配置多个主机名,apache只能使用ServerAlias来指定别名
    server_name testmoved.com testmoved2.com testmoved3.com;
    index index.html index.htm index.php;
    root /data/wwwroot/testmoved;
    #判断host是否为test.com
    if ($host != 'testmoved.com')
    {   
    rewrite ^/(.*)$ http://testmoved.com/$1 permanent;
    }
}

0c97499f09fce5867f473885c4673bac76c.jpg

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

e4fac493978e120c612122f8db7efd612c0.jpg

(ctrl+r 后输入 -t可以把上一次输入带有-t的命令列出来)
/usr/local/nginx/sbin/nginx -s reload
mkdir /data/wwwroot/testmoved
echo "重新定向测试成功" > /data/wwwroot/testmoved/index.html
curl -x127.0.0.1:80 testmoved.com/

48b2f1859def367b7016aa54ec3a91d5539.jpg

curl -x127.0.0.1:80 testmoved2.com/ -I

d47a86cb4f6aea2d85d6d35e20125f2440e.jpg

  
扩展
nginx.conf 配置详解:
http://www.ha97.com/5194.html    
http://my.oschina.net/duxuefeng/blog/34880 
nginx rewrite四种flag:
http://www.netingcn.com/nginx-rewrite-flag.html  http://unixman.blog.51cto.com/10163040/1711943

转载于:https://my.oschina.net/u/3867322/blog/1926878

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值