1

I am trying to make a reverse proxy with Lua script, Nginx is my proxy.

This is my .lua script part that makes the proxy_pass:

if content == "200" then
   proxy_pass https://5dea42df1eeb.ngrok.io;
   ngx.print("OK!")
else
   return ngx.exit (ngx.HTTP_NOT_ALLOWED)
end

I always get 500 internal server error. And this is ONLY happens when I put this line into my script:

proxy_pass https://5dea42df1eeb.ngrok.io;

Please let me know what could be wrong with my implementation

jrz
  • 1,213
  • 4
  • 20
  • 54
  • `proxy_pass` is not a Lua statement. It is a NIGNX directive. It was designed for using in a NGINX config file outside of Lua script – Egor Skriptunoff Mar 02 '21 at 14:09
  • @EgorSkriptunoff Is there a way to config my lua script to have proxy_pass? I want to make proxy_pass if and only if content == 200. And not through nginx.config. – jrz Mar 02 '21 at 14:18
  • @EgorSkriptunoff your advise is much needed here please. Thanks a lot. – jrz Mar 02 '21 at 18:36
  • Sorry, I didn't have experience with NGINX. Add "open-resty" tag to call for skilled users. – Egor Skriptunoff Mar 02 '21 at 18:44
  • @EgorSkriptunoff So there's no way to make reverse proxy from lua at all? – jrz Mar 03 '21 at 06:25
  • 2
    You can use [ngx.balancer](https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/balancer.md) to dynamically dispatch requests to upstreams. Check [this answer](https://stackoverflow.com/questions/53168425/how-to-dispatch-tcp-request-to-backends-with-first-byte-of-content-in-openresty/55250233#55250233) – un.def Mar 03 '21 at 06:37
  • @un.def Can you please take a look on this thread? https://stackoverflow.com/questions/66527896/lua-script-does-not-close-nginx-although-ngx-close-defined – jrz Mar 08 '21 at 10:13
  • @EgorSkriptunoff Can you also take a look on this thread? Critical for me.. https://stackoverflow.com/questions/66527896/lua-script-does-not-close-nginx-although-ngx-close-defined – jrz Mar 08 '21 at 11:09

0 Answers0