2. 使用rewrite规则实现将所有到a域名的访问rewrite到b域名
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
标签:www,rewrite,magedu,访问,域名,html,org From: https://www.cnblogs.com/biaoming534/p/16588178.html