用户访问www.taobao.com/a/b.html 跳转到www.tb.com/a/b.html
①
server {
server_name www.taobao.com
rewrite ^/(.*)$ http://www.tb.com/$1 permanent;
}
②
server {
server_name www.taobao.com www.tb.com
if ($host !='www.tb.com'){
rewrite ^/(.*)$ http://www.tb.com/$1 permanent;
}
}
2.用户访问域名跳转到应用的某个目录下 #proxy 后边有斜杠
例如访问www.baidu.com 跳转到后端的192.168.56.10:8080/admin
server {
listen 80;
server_name www.baidu.com;
location / {
proxy_pass http://192.168.56.10:8080/admin/;
}
}
3.例如访问www.baidu.com/admin 跳转到后端的192.168.56.10:8080/admin #proxy 后边没有有斜杠
server {
listen 80;
server_name www.baidu.com;
location /admin {
proxy_pass http://192.168.56.10:8080/admin;
}
}
4.访问目录或者特定的连接跳转
server {
listen 80;
server_name www.baidu.com;
location =/admin {
rewrite www.baidu.com;
}
location =/a/b.html {
rewrite www.baidu.com;
}
}