NGINX域名跳转案列

时间:2023-03-08 18:17:32

1、不同域名不同路径跳转

nginx实现a.com/teacher域名跳转到b.com/student

若想实现上面题目的跳转,目前鄙人知道两种方式:

1.return

2.proxy_pass

具体体现在NGINX配置文件如下:

 [root@dadong b]# cat /etc/nginx/nginx.conf
worker_processes ;
events {
worker_connections ;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout ;
server {
listen ;
server_name a.com;
location /teacher/ {
# return http://b.com/index.html; 第一种方法return
proxy_pass http://b.com/index.html; 第二种方法 proxy_pass
# root html/a;
# index index.html index.htm;
}
error_page /50x.html;
location = /50x.html {
root html;
}
}
server {
listen ;
server_name b.com;
location / {
root html/b;
index index.html index.htm;
}
error_page /50x.html;
location = /50x.html {
root html;
}
}
}

显示结果如下:

NGINX域名跳转案列

稍微有点差别的是我并没有在b.com站点下建立一个目录student。