我正在使用Nginx运行WebDAV。我有一个JS应用程序使用它作为存储。问题是WebDAV扩展正在删除我在配置中使用“add_header”添加的标头。
server {
# IP, Certificates, fullpath, autoindex ...
dav_methods PUT DELETE MKCOL COPY MOVE;
dav_ext_methods PROPFIND OPTIONS;
dav_access user:rw group:rw all:rw;
location / {
root /srv/http/content;
# Preflighted requests
if ($request_method = OPTIONS) {
add_header "Access-Control-Allow-Origin" *;
add_header "Access-Control-Allow-Methods" "GET, HEAD, POST, PUT, OPTIONS, MOVE, DELETE, COPY, LOCK, UNLOCK, PROPFIND";
add_header "Access-Control-Allow-Headers" "Authorization, Origin, X-Requested-With, Content-Type, Accept, DNT, X-CustomHeader, Keep-Alive,User-Agent, X-Requested-With, If-Modified-Since, Cache-Control, Content-Range, Range, Depth";
return 200;
}
if ($request_method = (GET|POST|HEAD|DELETE|PROPFIND)) {
add_header "Access-Control-Allow-Origin" *;
add_header "Access-Control-Allow-Methods" "GET, HEAD, POST, PUT, OPTIONS, MOVE, DELETE, COPY, LOCK, UNLOCK, PROPFIND";
add_header "Access-Control-Allow-Headers" "Authorization, Origin, X-Requested-With, Content-Type, Accept";
}
}
}
当我从我的应用程序打开WebDAV连接时,它请求OPTIONS
,然后是PROPFIND
。请求OPTIONS
通过正确的CORS标头传递,但PROPFIND
失败,因为没有设置CORS标头。请注意配置中OPTIONS
的特殊情况,我强制Nginx返回Http200
。然后出现标题。但是当让WebDAV完成时,所有CORS标题都会消失。
有人绕过这种行为吗?
实际上它是nginx的webdav中的一个错误。我能够使用lighttpd快速运行webdav(使用CORS,身份验证和SSL)。我的示例配置
server.port = 81
server.username = "http"
server.groupname = "http"
server.modules = (
"mod_webdav",
"mod_auth",
"mod_setenv", # before mod_status, very important!
"mod_status",
"mod_openssl"
)
server.document-root= "/srv/http/content"
server.errorlog = "/var/log/lighttpd/error.log"
ssl.engine = "enable"
ssl.pemfile = "/etc/ssl/webdav.key"
webdav.activate = "enable"
auth.backend = "htpasswd"
auth.backend.htpasswd.userfile = "/srv/http/passwd"
setenv.add-response-header = (
"Access-Control-Allow-Origin" => "*",
"Access-Control-Allow-Methods" => "GET, HEAD, POST, PUT, OPTIONS, MOVE, DELETE, COPY, LOCK, UNLOCK, PROPFIND",
"Access-Control-Allow-Headers" => "Authorization, Origin, X-Requested-With, Content-Type, Accept, DNT, X-CustomHeader, Keep-Alive,User-Agent, X-Requested-With, If-Modified-Since,Cache-Control, Content-Range, Range, Depth, Content-Length"
)
mimetype.assign = (
".html" => "text/html",
".txt" => "text/plain",
".css" => "text/css",
".js" => "application/x-javascript",
".jpg" => "image/jpeg",
".jpeg" => "image/jpeg",
".gif" => "image/gif",
".png" => "image/png",
"" => "application/octet-stream"
)