Hi I am using Nginx together with njs and have such location in my config
server { listen 80 default_server; listen [::]:80 default_server; server_name _; root /usr/share/nginx/html; error_log stderr debug; ... location /checkout/payment { js_content http.payment; } location /tc/api/endpoint { proxy_ssl_server_name on; proxy_ssl_name some_proxy_host; subrequest_output_buffer_size 1m; proxy_read_timeout 300; proxy_buffer_size 128k; proxy_buffers 8 128k; proxy_busy_buffers_size 128k; proxy_set_header Accept "application/json, text/plain, */*"; proxy_set_header X-TC-Domain some_domain; # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Content-Type 'application/json'; proxy_set_header Authorization "[[AUTH_TOKEN]]"; proxy_pass https://some_proxy_host; proxy_redirect / /; proxy_intercept_errors on; error_page 301 302 307 = @handle_redirect; }
Inside of njs file I am making POST request to API
function payment(req) { if (req.method === 'GET') { return returnIndex(req); } else { req.subrequest('/tc/api/endpoint/book', { body: JSON.stringify({ ... }), method: 'POST', }).then(payment => { return returnIndex(req); }).catch(() => { return returnIndex(req); }); } }
In this request I am getting body response as formdata converting it to JSON and making POST request to 3rd party with following error.
*63 open() “/usr/share/nginx/html//tc/api/endpoint/book” failed (2: No such file or directory) while sending to client, client: 10.0.0.14, server: _, request: “POST /checkout/payment?key=val HTTP/1.1”, subrequest: “/tc/api/endpoint/book”, upstream: “https://11.100.216.19:443//book”, host: “proxy.eu-west-2.elb.amazonaws.com”
This request should be proxied to 3rd party but looks like it trying to open file but not making redirect. This issue is reproducing only in my AWS account and Nginx is hosted after CloudFront. Locally it’s working well. Any ideas why it’s happening?
Advertisement
Answer
The issue was in requested API. Nginx had such behavior because of 405 status code of response