HTTP API fails to display payload


(Lucian Davidescu) #1

I have this situation that’s a bit puzzling to me. I’m trying to use the HTTP API for server-side analytics with Openresty (Nginx+Lua). I have this code that, in a similar composition, works with Google Analytics Measurement Protocol…

	location = /mylocation {
            access_by_lua_block  {
	        local request = {
			idsite = 1,
        	        rec = 1,
			_id = ngx.md5(ngx.var.remote_addr .. ngx.var.http_user_agent),
			cip = ngx.var.remote_addr,
    	   	        url = ngx.var.request_uri,
			urlref = ngx.var.http_referer,
			ua = ngx.var.http_user_agent,
			lang = string.sub(ngx.var.http_accept_language, 1, 2),
                        token_auth = "1234567890abcdef1234567890abcdef"
        	}
        	local res = ngx.location.capture(  "/gamp",  {
        	method = ngx.HTTP_POST,
        	body = ngx.encode_args(request)
        	})
            }
	}

	location = /gamp {
		internal;
		expires epoch;
		access_log off;
		proxy_pass_request_headers off;
		proxy_pass_request_body on;
		proxy_pass http://mysite.example.com/matomo/piwik.php;
		# alternate endpoint # proxy_pass http://mysite.example.com/test.php;
		}

…but not with Matomo (no hit shows up in the dashboard).

If I put in a test endpoint instead of Matomo’s, the load will show up there fine. Moreover, if I take that same payload from the test endpoint and manually curl (post) it to Matomo, the hit finally shows in the dashboard!

But the direct connexion won’t work. Any idea why or how to fix this?

L.E. I put in the token_auth too, still no go.