nginx反向代理和rewrite进行解决跨域问题 去掉url中的一部分字符串,通过nginx正则生成新的url

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               

场景:表面上访问的是http://127.0.0.1:7777/test/xhtml//tpl/app-tpl-webapp/css/base.css,

实际上看的是http://127.0.0.1:8888/tpl/app-tpl-webapp/css/base.css的内容。


server {

  listen 7777;
  server_name 127.0.0.1;
  
  location ^~ /website-webapp {
            proxy_pass http://127.0.0.1:8888;
        }
  
        location ^~ /app-tpl-webapp {
            proxy_pass http://127.0.0.1:8888;
        }
  
  location ^~ /tpl {
            proxy_pass http://127.0.0.1:8888;
        }
   
  location ~ .*/tpl/ {
      #alias E:/UCMSServer/tomcat/webapps/tpl/;
                    #index  index.shtml index.html index.htm;
        
   rewrite ^/(.*)/tpl/(.*)$ http://127.0.0.1:7777/tpl/$2;       #其中$2表示的是正则中的第二串
  }  
  
        location ^~ /preview {
            proxy_pass http://127.0.0.1:8888;
        } 

 }


以下方式是正则匹配以mp4结尾的方式

location ~ \.mp4$ {
      root /data;
      mp4;
                mp4_buffer_size       1m;
                mp4_max_buffer_size   500m;
     }

           

给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow

这里写图片描述

猜你喜欢

转载自blog.csdn.net/jdtugfcg/article/details/84025202