当前位置:   article > 正文

使用rewrite规则实现将所有到a域名的访问rewrite到b域名_bbb,c0m

bbb,c0m

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

[root@centos8 ~]#vim /apps/nginx/conf.d/pc.conf
server {
	listen 80;
	server_name www.aaa.com;
	location / {
        root /data/nginx/html/pc;
        index index.html;
        rewrite / http://www.bbb.com redirect;
	}
}

server {
	listen 80;
	server_name www.bbb.com;
	location / {
        root /dara/nginx/html/mobile;
        index index.html;
	}
}

[root@centos8 ~]#echo aaa > /data/nginx/html/pc/index.html
[root@centos8 ~]#echo bbb > /data/nginx/html/mobile/index.html

[root@ubuntu18 ~]#vim /etc/hosts
10.0.0.58  www.aaa.com www.bbb.com

[root@ubuntu18 ~]#curl www.aaa.com
<html>
<head><title>302 Found</title></head>
<body>
<center><h1>302 Found</h1></center>
<hr><center>nginx/1.18.0</center>
</body>
</html>

[root@ubuntu18 ~]#curl -L www.aaa.com
bbb

[root@ubuntu18 ~]#curl www.aaa.com -Lv (-L跟随跳转-v显示细节)
* Rebuilt URL to: www.aaa.com/
*   Trying 10.0.0.58...
* TCP_NODELAY set
* Connected to www.aaa.com (10.0.0.58) port 80 (#0)
> GET / HTTP/1.1
> Host: www.aaa.com
> User-Agent: curl/7.58.0
> Accept: */*
> 
< HTTP/1.1 301 Moved Permanently
< Server: nginx
< Date: Fri, 01 Jul 2022 07:22:29 GMT
< Content-Type: text/html
< Content-Length: 162
< Connection: keep-alive
< Location: http://www.bbb.com
< 
* Ignoring the response-body
* Connection #0 to host www.aaa.com left intact
* Issue another request to this URL: 'http://www.bbb.com'
* Rebuilt URL to: http://www.bbb.com/
*   Trying 209.17.116.160...
* TCP_NODELAY set
* Connected to www.bbb.com (209.17.116.160) port 80 (#1)
> GET / HTTP/1.1
> Host: www.bbb.com
> User-Agent: curl/7.58.0
> Accept: */*
> 
< HTTP/1.1 301 Moved Permanently
< Server: openresty/1.19.9.1
< Date: Fri, 01 Jul 2022 07:22:32 GMT
< Content-Type: text/html
< Content-Length: 175
< Connection: keep-alive
< Location: https://www.bbb.com/
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号