I'm writing a nginx module which is expected to load load a remote file before sending a reply to the client.
The user passes an ID in the URL. I use that ID to load a URL to the remote file. My test looks something like this:
wget http://example.com/?id=123
The id 123
gets transformed to a URL such as
http://other.example.com/image/cute.png
Now I need to load cute.png
from within my nginx
module. Can I do that with an ngx_request
or maybe an ngx_upstream
? I've not been able to find any clear documentation that would show how to do that...
Update:
I've now (finally!) found the sub-request function:
ngx_int_t rc;
ngx_str_t uri;
ngx_http_request_t *sr;
...
/* THIS IS WHAT WAS WRONG */
ngx_str_set(&uri, "http://other.example.com/image/cute.png");
rc = ngx_http_subrequest(r, &uri, NULL, &sr, NULL, 0);
if (rc != NGX_OK) {
/* error */
}
However, instead of the answer from the 3rd party website, I'm getting 404 errors with the following HTML code:
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.10.3 (Ubuntu)</center>
</body>
</html>
My feeling is that right now it queries my nginx server instead of using an external TCP connection to get the file from the 3rd party website...
Any idea whay could be wrong in such a simple statement?