#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent; location __PATH__/stream { proxy_pass http://127.0.0.1:__PORT__/stream; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_connect_timeout 7m; proxy_send_timeout 7m; proxy_read_timeout 7m; } location __PATH__/UP { access_by_lua_block{ local json=require("cjson") ngx.req.read_body() local req = ngx.req.get_body_data() local newreq = { ["message"] = req } local body = json.encode(newreq) ngx.req.set_body_data(body) } if ($request_method = GET ) { return 200 '{"unifiedpush":{"version":1}}'; } proxy_set_header Content-Type application/json; proxy_pass http://127.0.0.1:__PORT__/message; proxy_set_header Host $host; } location __PATH__/ { proxy_pass http://127.0.0.1:__PORT__/; #sub_path_only rewrite ^/__PATH__(/.*) $1 break; proxy_set_header Host $host; proxy_buffering off; fastcgi_param REMOTE_USER $remote_user; client_max_body_size 50M; more_set_input_headers 'Authorization: $http_authorization'; proxy_set_header Authorization $http_authorization; }