当前位置:网站首页>Openresty rewrites the location of 302

Openresty rewrites the location of 302

2022-07-01 04:38:00 tuhoooo

introduction

This paper introduces the use of openresty modify 302 Methods for redirecting addresses and parameters , Be able to deal with the problem of inconsistent internal and external network access ;openresty Integrated lua And many practical tools and templates , Than nginx It should be more convenient ;proxy_redirect The drawback is that you can only modify the domain name and port , Can't cope well with complex situations .

Original address : http://blog.duhbb.com/2022/02/15/usage-of-openresty-in-rewriting-302-location/

Welcome to my blog : http://blog.duhbb.com/

Problem solved

Hey , openresty It's really an artifact , YYDS!

file

Above use lua modify nginx 302 Reset backward Location, To cause to Location The Intranet in becomes the address accessed by the Internet .

The counterpart is :

body_filter_by_lua

  • Get the response data of all requests
  • Sensitive information detection for all requested response data
  • Sensitive data detected returned , Conduct desensitization before responding

Be careful :

  • The document says body_filter_by_lua May be called multiple times in one request
  • When the code runs to body_filter_by_lua when ,HTTP Headlines (header) It's already sent . If the header related to the response body is set before , And body_filter_by_lua The response body is modified in , This will cause inconsistency between the response header and the actual response . A simple example : Suppose the upstream server returns Content-Length Headlines , and body_filter_by_lua The actual size of the response body is also modified . After the client receives this header , If you press Content-Length To deal with , Then he will fall into the pit . because Nginx Streaming response of , The headlines are like water thrown out , You can only modify it in advance .OpenResty Provide with body_filter_by_lua Corresponding header_filter_by_lua.

Reference documents

  • https://blog.csdn.net/weixin_33734785/article/details/89124813
  • https://blog.csdn.net/ygm_linux/article/details/81563129
  • https://blog.csdn.net/wtswjtu/article/details/38898945
  • https://zhuanlan.zhihu.com/p/67904411

Conclusion

This paper introduces the use of openresty modify 302 Methods for redirecting addresses and parameters , Be able to deal with the problem of inconsistent internal and external network access ;openresty Integrated lua And many practical tools and templates , Than nginx It should be more convenient ;proxy_redirect The drawback is that you can only modify the domain name and port , Can't cope well with complex situations .

Original address : http://blog.duhbb.com/2022/02/15/usage-of-openresty-in-rewriting-302-location/

Welcome to my blog : http://blog.duhbb.com/

原网站

版权声明
本文为[tuhoooo]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202160249102480.html