Search code examples
nginxrequestwebdavput

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?


Solution

  • 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..
        }
    
    }