Nginx – How to Reply with 200 Without Serving a File

htmlhttpnginx

I have configured Apache to send back a 200 response without serving any file with this configuration line

Redirect 200 /hello

Can I do this with Nginx? I don't want to serve a file, I just want the server to respond with a 200 (I'm just logging the request).

I know I can add an index file and achieve the same thing, but doing it in the config means there's one less thing that can go wrong.

Best Answer

Yes, you can

location / {
    return 200 'gangnam style!';
    # because default content-type is application/octet-stream,
    # browser will offer to "save the file"...
    # if you want to see reply in browser, uncomment next line 
    # add_header Content-Type text/plain;
}