nginx代理的几种场景分析

nginx中对/的处理方式不同
我们访问路径:http://localhost/proxy/test.html 进行分析:

场景1:
location /proxy/ {
   proxy_pass http://loalhost/;
}

代理到http://localhost/test.html

场景2:
location /proxy/ {
   proxy_pass http://localhost;
}

代理到http://localhost/proxy/test.html

场景3:
location /proxy/ {
   proxy_pass http://localhost/home/;
}

代理到http://localhost/home/test.html

场景4:
location /proxy/ {
   proxy_pass http://localhost/home;
}

代理到http://localhost/hometest.html

其他

1.隐性地址跳转(通过user-agent判断ios和android)

location /article/html/tutorial.html {
    if ( $http_user_agent ~* "iPhone" ){
       rewrite ^/article/html/tutorial.html$ /article/html/tutorial_ios.html last; 
       break;
    } 
    root /Users/hecj/workspace/dist;
}

注:上面这个不会改变地址栏url

2.显性地址跳转

location /article/html/tutorial.html {
     if ( $http_user_agent ~* "iPhone" ){
        rewrite ^(.*) http://test.com/article/html/tutorial_ios.html permanent; 
        break;
      } 
      root /Users/hecj/workspace/dist;
}

注:上面这个会改变地址栏url

3.隐性地址跳转

   location /renrendict.html {
        proxy_pass http://test.com/html/download/renrendict.html;
    }

你可能感兴趣的:(nginx)