使用下面的配置,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 copy to」未被重寫,然後無法開啟它,回傳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
這次真是萬分感謝。我使用 NGINX 作為 https 代理到透過 http 運行 WebDAV 的後端 IIS 伺服器時遇到了類似的問題。
正在傳遞的 MOVE 請求中的目標標頭是 https:// 位址,但我從後端伺服器收到 400 錯誤,因為它是透過 http 運行的。我需要將 Destination 標頭從 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 請求