1. 程式人生 > >nginx新舊域名過度以及跳轉

nginx新舊域名過度以及跳轉

nginx

  • www.taobao.com #域名過期跳轉到www.tb.com

  • 用戶訪問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;

    }

    }


    nginx新舊域名過度以及跳轉