Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 77 down vote accepted

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;
share|improve this answer
how do I add a newline to the response? gangnam\nstyle? – tback Dec 28 '15 at 13:52
@tback of course, right you are – cadmi Mar 9 at 9:10
Just add the newline! Nginx configuration directives are not bound to single lines, they are ended by semicolon. – Emil Vikström May 3 at 19:26

You do need to use a 204 as Nginx will not allow a 200 with no response body. To send a 204 you simply use the return directive to return 204; in the appropriate location.

share|improve this answer

As per status code definitions, I believe you want it to be a 204, and not 200. 200's need to be with a resource in the response, or I'd suspect most sane browsers would get confused by this. The other one you can use is 304, which is for cached content.

share|improve this answer
Sure, make it a 204, how do I do it? Although I very much doubt any browser will be confused by an empty body. – Theo Nov 1 '10 at 15:55
an empty body is still a response, with an object, such as a blank index.html. What you asked is to provide a 200 response with no resource attached to it (no file served). As for how exactly to do it on nginx, I need to look it up myself, I've only once done this on apache, and I can't remember off hand. – sandroid Nov 1 '10 at 20:05
304 seems like it would send all the wrong signals for things like debugging and temporary returns. – Kzqai Feb 5 at 20:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.