Nginx에서 WebDav http Destination 요청 헤더를 다시 작성하는 방법

Nginx에서 WebDav http Destination 요청 헤더를 다시 작성하는 방법

아래 구성을 사용하면 GET, PUT, MKCOL 등은 잘 작동하지만 MOVE 및 COPY는 작동하지 않습니다.

server {
    listen 80 ;
    listen [::]:80 ;
    server_name _;
    root /var/www/html;

    charset     utf-8;
    error_log  /var/log/nginx/error.log debug;
    rewrite_log on;

    auth_pam "WebDav auth";
    auth_pam_service_name "nginx";

    location /dav/ {
        autoindex on;
        client_body_temp_path /var/www/tmp;

        rewrite ^/dav/(.*)$ /dav/$remote_user/$1 break;

        dav_methods PUT DELETE MKCOL COPY MOVE;
        dav_ext_methods PROPFIND OPTIONS;
        dav_access user:rw group:rw all:r;
        create_full_put_path on;
    }
}

디버그 로그에는 'http 복사 대상'이 다시 작성되지 않았으며 이를 열지 못했고 500 오류가 반환되었다고 표시됩니다. 대상 http 요청 헤더를 다시 작성하고 다음과 같이 시도해야 한다고 생각합니다.

set $destination $http_destination;
if ($destination ~ ^(http://www.foobar.test/dav)/(.*)$) {
    set $destination $1/$remote_user/$2;
    set $http_destination $destination;
}

하지만 그것도 작동하지 않습니다. 다시 쓰기 지시문을 사용하여 WebDav를 작동하는 방법을 알려주시겠습니까?

답변1

소음이 발생해서 죄송합니다. 사용하여 자체 해결헤더-더-nginx-모듈. 전체 간단한 구성은 다음과 같습니다.

server {
    listen 80 ;
    listen [::]:80 ;
    server_name _;
    root /var/www/html;
    charset     utf-8;

    auth_pam "WebDav auth";
    auth_pam_service_name "nginx";

    location /dav/ {
        set $destination $http_destination;
        if ($destination ~ ^(http://www.foobar.test/dav)/(.*)$) {
            set $destination $1/$remote_user/$2;
            more_set_input_headers "Destination: $destination";
        }

        rewrite ^/dav/(.*)$ /dav/$remote_user/$1 break;

        dav_methods PUT DELETE MKCOL COPY MOVE;
        dav_ext_methods PROPFIND OPTIONS;
        dav_access user:rw group:rw all:r;
        create_full_put_path on;
    }
}

답변2

감사합니다. http를 통해 WebDAV를 실행하는 백엔드 IIS 서버에 대한 https 프록시로 NGINX를 사용하는 것과 비슷한 문제가 있었습니다.

전달된 MOVE 요청의 대상 헤더는 https:// 주소였지만 http를 통해 실행 중이었기 때문에 백엔드 서버로부터 400 오류를 수신했습니다. 대상 헤더를 https://에서 http://로 수정해야 하므로 다음을 사용했습니다.

 set $destination $http_destination;
    if ($destination ~ ^(https://webdav.mydomain.com)/(.*)$) {
        set $destination "http://webdav.mydomain.com/$2";
        more_set_input_headers "Destination: $destination";
    }

이로 인해 성공적인 MOVE 요청이 허용되었습니다.

관련 정보