Alexander Klimenko
Alexander Klimenko

Reputation: 2280

Turn on nginx `client_body_in_file_only` for PUT method only

I'm building webdav backend application with nginx as a frontend. To reduce disc operations during upload I'm turning on client_body_in_file_only. The problem is that this forces nginx to write down all of request bodies and slows down small requests (PROPFIND queries for example).

Is there any way to make nginx client_body_in_file_only=on for PUT methods only?

Upvotes: 1

Views: 3526

Answers (1)

Tan Hong Tat
Tan Hong Tat

Reputation: 6879

If the $request_method is "PUT", return "588", which will be handled by the named location block that has the client_body_in_file_only=on;.

server {

    error_page 588 = @saveinfile;

    if ($request_method = PUT) {
        return 588;
    }
    location / {

        # the usual stuff..
    }
    location @saveinfile {            
        client_body_in_file_only on;

        # the usual stuff..
    }

}

Upvotes: 4

Related Questions