:: krowemoh

Thursday | 26 DEC 2024
Posts Links Other About Now

previous
next

Returning Strings in Nginx

2022-11-17

This was a proof of concept for my form submission note. I wanted to have nginx send back a response when it got some post data. I would have loved to have returned the post data itself but for some reason request_body was blank and I didn't want to dig into it.

Regardless, returning just a string worked perfectly!

server {
    ...
    location /some-endpoint {
        if ($request_method = POST ) {
            add_header Content-Type text/plain;
            return 200 'Processed!';
        }
    }
}

This block simply returns back some text if it receives a POST request.

This is for:

https://nivethan.dev/devlog/submitting-forms-without-page-change.html