1、不同域名不同路径跳转
nginx实现a.com/teacher域名跳转到b.com/student
若想实现上面题目的跳转,目前鄙人知道两种方式:
1.return
2.proxy_pass
具体体现在NGINX配置文件如下:
1 [[email protected] b]# cat /etc/nginx/nginx.conf 2 worker_processes 1; 3 events { 4 worker_connections 1024; 5 } 6 http { 7 include mime.types; 8 default_type application/octet-stream; 9 sendfile on; 10 keepalive_timeout 65; 11 server { 12 listen 80; 13 server_name a.com; 14 location /teacher/ { 15 # return http://b.com/index.html; 第一种方法return 16 proxy_pass http://b.com/index.html; 第二种方法 proxy_pass 17 # root html/a; 18 # index index.html index.htm; 19 } 20 error_page 500 502 503 504 /50x.html; 21 location = /50x.html { 22 root html; 23 } 24 } 25 server { 26 listen 80; 27 server_name b.com; 28 location / { 29 root html/b; 30 index index.html index.htm; 31 } 32 error_page 500 502 503 504 /50x.html; 33 location = /50x.html { 34 root html; 35 } 36 } 37 }
显示结果如下:
稍微有点差别的是我并没有在b.com站点下建立一个目录student。
原文地址:https://www.cnblogs.com/dadonggg/p/9058572.html
时间: 2024-11-08 16:48:22