-
Notifications
You must be signed in to change notification settings - Fork 43
/
nginx.conf
236 lines (171 loc) · 6.67 KB
/
nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
daemon off;
user abc abc;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
dav_ext_lock_zone zone=foo:10m;
send_timeout 3600;
client_body_timeout 3600;
keepalive_timeout 3600;
lingering_timeout 3600;
client_max_body_size 10G;
create_full_put_path on;
min_delete_depth 0;
server {
server_name localhost;
listen 80;
listen [::]:80;
set $destination $http_destination;
set $new_path "";
set $webdav_root "/data";
set $checkPropfind "";
location ~ \.(_.*|DS_Store|Spotlight-V100|TemporaryItems|Trashes|hidden|localized)$ {
access_log off;
error_log off;
if ($request_method = PUT) {
return 403;
}
return 404;
}
location ~ \.metadata_never_index$ {
return 200 "Don't index this drive, Finder!";
}
# With fixes for Windows from http://netlab.dhis.org/wiki/ru:software:nginx:webdav
location / {
auth_basic "Restricted";
auth_basic_user_file htpasswd;
dav_ext_lock zone=foo;
dav_methods PUT MKCOL;
dav_ext_methods OPTIONS LOCK UNLOCK;
autoindex on;
autoindex_exact_size on;
autoindex_localtime on;
fancyindex on;
fancyindex_exact_size off;
fancyindex_localtime on;
fancyindex_name_length 255;
root $webdav_root;
error_page 599 = @propfind_handler;
error_page 598 = @delete_handler;
error_page 597 = @copy_move_handler;
error_page 596 = @propfind_withdepth_handler;
open_file_cache off;
if ($request_method != OPTIONS) {
# CORS
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Credentials' 'true' always;
add_header 'Access-Control-Allow-Methods' 'OPTIONS, GET, HEAD, POST, PUT, MKCOL, MOVE, COPY, DELETE, PROPFIND, PROPPATCH, LOCK, UNLOCK' always;
add_header 'Access-Control-Allow-Headers' 'Authorization,DNT,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,X-Accept-Charset,X-Accept,origin,accept,if-match,destination,overwrite' always;
add_header 'Access-Control-Expose-Headers' 'ETag' always;
add_header 'Access-Control-Max-Age' 1728000 always;
}
if ($request_method = OPTIONS) {
# CORS
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'OPTIONS, GET, HEAD, POST, PUT, MKCOL, MOVE, COPY, DELETE, PROPFIND, PROPPATCH, LOCK, UNLOCK';
add_header 'Access-Control-Allow-Headers' 'Authorization,DNT,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,X-Accept-Charset,X-Accept,origin,accept,if-match,destination,overwrite';
add_header 'Access-Control-Expose-Headers' 'ETag';
add_header 'Access-Control-Max-Age' 1728000;
# WebDAV compliance
add_header Allow 'OPTIONS, GET, HEAD, POST, PUT, MKCOL, MOVE, COPY, DELETE, PROPFIND, PROPPATCH, LOCK, UNLOCK';
add_header DAV '1, 2';
return 200;
}
if ($request_method = PROPFIND) { # Normal flow for PROPFIND
set $checkPropfind "propfind";
}
if ($http_depth = 0) { # FIX for Depth = 0 allowed unauthenticated
set $checkPropfind "${checkPropfind}+withDepth";
}
if ($http_depth = 1) { # FIX for Depth = 1 allowed unauthenticated
set $checkPropfind "${checkPropfind}+withDepth";
}
if ($checkPropfind = "propfind") { # Normal flow for PROPFIND
return 599;
}
if ($checkPropfind = "propfind+withDepth") { # FIX for Depth = 1 allowed unauthenticated
return 596;
}
if ($request_method = PROPPATCH) { # Unsupported, allways return OK.
add_header Content-Type 'text/xml';
return 207 '<?xml version="1.0"?><a:multistatus xmlns:a="DAV:"><a:response><a:propstat><a:status>HTTP/1.1 200 OK</a:status></a:propstat></a:response></a:multistatus>';
}
if ($request_method = MKCOL) { # Microsoft specific handle: add trailing slash.
rewrite ^(?<captured_path>.*[^/])$ $captured_path/ break;
}
if ($request_method = DELETE) {
return 598;
}
if ($request_method = COPY) {
return 597;
}
if ($request_method = MOVE) {
return 597;
}
include conf.d/location.conf;
}
location @propfind_handler {
internal;
open_file_cache off;
if (!-e $webdav_root/$uri) { # Microsoft specific handle.
return 404;
}
root $webdav_root;
dav_ext_methods PROPFIND;
}
location @propfind_withdepth_handler { # Same as above but authenticated.
auth_basic "Restricted";
auth_basic_user_file htpasswd;
internal;
open_file_cache off;
if (!-e $webdav_root/$uri) { # Microsoft specific handle.
return 404;
}
root $webdav_root;
dav_ext_methods PROPFIND;
}
location @delete_handler {
auth_basic "Restricted";
auth_basic_user_file htpasswd;
internal;
open_file_cache off;
if ($destination ~ ^https?://(?<captured_path>.*)$) {
set $new_path $captured_path;
more_set_input_headers "Destination: http://$new_path";
}
if (-d $webdav_root/$uri) { # Microsoft specific handle: Add trailing slash to dirs.
more_set_input_headers "Destination: http://$new_path/";
rewrite ^(?<captured_path>.*[^/])$ $captured_path/ break;
}
root $webdav_root;
dav_methods DELETE;
}
location @copy_move_handler {
auth_basic "Restricted";
auth_basic_user_file htpasswd;
internal;
open_file_cache off;
if ($destination ~ ^https?://(?<captured_path>.*)$) {
set $new_path $captured_path;
more_set_input_headers "Destination: http://$new_path";
}
if (-d $webdav_root/$uri) { # Microsoft specific handle: Add trailing slash to dirs.
more_set_input_headers "Destination: http://$new_path/";
rewrite ^(?<captured_path>.*[^/])$ $captured_path/ break;
}
root $webdav_root;
dav_methods COPY MOVE;
}
include conf.d/server.conf;
}
include conf.d/http.conf;
}