2018-09-06 nginx域名带目录转发

nginx域名带目录转发,转发时希望保留目录名:

location /click {
proxy_pass http://ups_click;
proxy_store off;
proxy_redirect off;
proxy_set_header X-Forwarded-For remote_addr;
proxy_set_header Host $http_host;
}

    location /MobCastle_UI_new {
            alias /home/arch/MobCastle_UI_new_v7;
            index login.html index.html index.htm;
    }

nginx域名带目录转发,转发时希望去掉目录名或者修改目录名:

    location /jdevent {
            proxy_pass http://172.17.0.4:9097/jdevent;
            proxy_store off;
            proxy_redirect off;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Host $http_host;
    }

    location /MobCastle_UI_new {
     rewrite ^/MobCastle_UI_new/(.*) http://$host/$1 permanent;

alias /home/arch/MobCastle_UI_new_v7;

index login.html index.html index.htm;

    }

    location /wx/ {
    proxy_pass http://172.17.0.17:8000/wx/;
    proxy_store off;
    proxy_redirect off;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $http_host;

}

    location /MobCastle_N {

alias /home/arch/MobCastle_N-v1;

index login.html index.html index.htm;

使用下面的重定向301可以确保静态资源的缓存没有问题

     rewrite ^/MobCastle_N/(.*) http://$host/$1 permanent;
    }

rewrite ^/(.*) http://ad.66173yx.com/website.php?act=general&id=1083 permanent;

    location /aso {
     rewrite ^/aso(.*) http://ad.66173yx.com/website.php?act=general&id=1083 permanent;
    }

    location /aso/ {
     rewrite ^/aso/(.*) http://ad.66173yx.com/website.php?act=general&id=1083 permanent;
     #rewrite ^/aso/(.*) http://zdjs.yxtop10.com/$1 permanent;
    }

location /minigame {
            rewrite ^/minigame/(.*) /$1 break;
            proxy_pass http://123.56.23.XXX:8000;
            proxy_store off;
            proxy_redirect off;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Host $http_host;
}

location /gamecube {
            proxy_pass https://10.10.10.14/;
            proxy_store off;
            proxy_redirect off;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Host $http_host;
}

最后两个表明,匹配到目录后:

rewrite ^/minigame/(.*) /$1 break;
proxy_pass http://123.56.23.XXX:8000;

等价于

proxy_pass http://123.56.23.XXX:8000/;

取决于 proxy_pass的地址是否以"/"结束,是则原目录名丢弃。

你可能感兴趣的:(2018-09-06 nginx域名带目录转发)