我有以下设置:
location @public { auth_basic off;}location @webdav { proxy_set_header主机$ host; proxy_pass http:// localhost:8080;}地点 / { #WebDAV服务器 …
结果证明问题是nginx进程阻塞的顺序。首先执行两个嵌套的位置块,然后才执行父位置语句。由于我的嵌套位置块都返回,因此永远不会到达父位置语句。解决方案是将我的WebDAV代码添加到每个嵌套位置块的开头。最终代码:
location @public { auth_basic off; } location @webdav { proxy_set_header Host $host; proxy_pass http://localhost:8080; } location / { # WebDAV server if ($request_method != GET) { error_page 418 = @webdav; return 418; } gzip on; fancyindex on; location ~ /(public|\.well-known)/ { # WebDAV server if ($request_method != GET) { error_page 418 = @webdav; return 418; } if ($remote_user = "") { error_page 418 = @public; return 418; } } location = /robots.txt { # WebDAV server if ($request_method != GET) { error_page 418 = @webdav; return 418; } add_header Content-Type text/plain; return 200 "User-agent: *\nDisallow: /\n"; } }