feat(proxy): use lua http module

This commit is contained in:
CyberL1 2025-01-10 06:54:47 -05:00
parent 62c6b8357d
commit 275a43fc18
3 changed files with 10 additions and 5 deletions

View File

@ -8,11 +8,11 @@ services:
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
proxy:
image: openresty/openresty:alpine-fat
build: proxy
env_file: .env
ports:
- 80:80
volumes:
- ./proxy.conf:/etc/nginx/conf.d/proxy.conf.template
- ./proxy/proxy.conf.template:/etc/nginx/conf.d/proxy.conf.template
network_mode: host
command: /bin/sh -c "sed 's/{PROXY_DOMAIN}/$PROXY_DOMAIN/' /etc/nginx/conf.d/proxy.conf.template > /etc/nginx/conf.d/proxy.conf && nginx -g 'daemon off;'"

5
proxy/Dockerfile Normal file
View File

@ -0,0 +1,5 @@
FROM openresty/openresty:alpine
RUN wget -O /usr/local/openresty/lualib/resty/http.lua https://github.com/ledgetech/lua-resty-http/raw/refs/heads/master/lib/resty/http.lua
RUN wget -O /usr/local/openresty/lualib/resty/http_connect.lua https://github.com/ledgetech/lua-resty-http/raw/refs/heads/master/lib/resty/http_connect.lua
RUN wget -O /usr/local/openresty/lualib/resty/http_headers.lua https://github.com/ledgetech/lua-resty-http/raw/refs/heads/master/lib/resty/http_headers.lua

View File

@ -22,10 +22,10 @@ server {
set $ip '';
rewrite_by_lua_block {
local shell = require("resty.shell")
local http = require("resty.http").new()
local ok, stdout, strerr, reason, status = shell.run("curl http://127.0.0.1:3000/containers/" .. ngx.var.container .. "/ip")
ngx.var.ip = stdout
local res, err = http:request_uri("http://127.0.0.1:3000/containers/" .. ngx.var.container .. "/ip")
ngx.var.ip = res.body
}
proxy_pass http://$ip:$port;