2. 使用rewrite规则实现将所有到a域名的访问rewrite到b域名

2. 使用rewrite规则实现将所有到a域名的访问rewriteb域名

a域名:www.magedu.org

b域名:m.magedu.org

 

a域名配置  #a域名的所有的连接都临时跳转到b域名

 

server {

        listen       80;

        server_name www.magedu.org;

        root /data/nginx/html/pc;

        default_type text/html;

        location / {

            root /data/nginx/html/pc;

            rewrite / http://m.magedu.org redirect;

        }

}

 

b域名配置

server {

        listen       80;

        server_name m.magedu.org;

        root /data/nginx/html/mobile;

        location / {

            root /data/nginx/html/mobile;

        }

}

 

 

#测试访问

[root@CentOS8 mobile]# curl www.magedu.org -Lv

* Rebuilt URL to: www.magedu.org/

*   Trying 10.0.0.8...

* TCP_NODELAY set

* Connected to www.magedu.org (10.0.0.8) port 80 (#0)

> GET / HTTP/1.1

> Host: www.magedu.org

> User-Agent: curl/7.61.1

> Accept: */*

>

< HTTP/1.1 302 Moved Temporarily

< Server: nginx/1.18.0

< Date: Sat, 13 Aug 2022 17:05:01 GMT

< Content-Type: text/html

< Content-Length: 145

< Connection: keep-alive

< Location: http://m.magedu.org

<

* Ignoring the response-body

* Connection #0 to host www.magedu.org left intact

* Issue another request to this URL: 'http://m.magedu.org'

* Rebuilt URL to: http://m.magedu.org/

*   Trying 10.0.0.8...

* TCP_NODELAY set

* Connected to m

posted @   惊起千层浪  阅读(85)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
点击右上角即可分享
微信分享提示