I have a rewrite url need setup basic authentication
example: /v2/log/api/

solved:

        location /v2/log/api {
                auth_basic "V2 API Authencation";
                auth_basic_user_file /path_to_auth_file;
                error_page 404 = @logv2;
        }
        location @logv2 {
            rewrite  ^(.*)$ /index.php last;
        }