server { listen 80; resolver ${RESOLVER} ipv6=off; location /_matrix/push/v1/notify { set $target ''; if ($request_method = GET ) { return 200 '{"gateway":"matrix"}'; } access_by_lua_block { local cjson = require("cjson") ngx.req.read_body() local body = ngx.req.get_body_data() local parsedBody = cjson.decode(body) ngx.var.target = parsedBody["notification"]["devices"][1]["pushkey"] ngx.req.set_body_data(body) } proxy_set_header Content-Type application/json; proxy_set_header Host $host; proxy_pass $target; proxy_ssl_server_name on; } location /UP { access_by_lua_block{ ngx.req.read_body() local req = ngx.req.get_body_data() local newreq, n, err = ngx.re.gsub(req, '\\\\', '\\\\') local newreq, n, err = ngx.re.gsub(newreq, '"', '\\"') local newreq, n, err = ngx.re.gsub(newreq, "^", "{\"message\":\"") local newreq, n, err = ngx.re.gsub(newreq, "$", "\"}") ngx.req.set_body_data(newreq) } proxy_set_header Content-Type application/json; proxy_set_header Host $host; proxy_pass ${GOTIFY_URL}/message; proxy_ssl_server_name on; } }