-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnginx.conf
82 lines (64 loc) · 3.02 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
server {
listen 8080;
client_max_body_size 0;
root $NGINX_FOLDER;
create_full_put_path on;
autoindex_exact_size off;
autoindex_localtime on;
charset utf-8;
port_in_redirect off;
try_files $uri $uri/ /index.html;
location ^~ /$BLOGS_FOLDER {
return 403;
location ~* /$BLOGS_FOLDER/(?<username>([^/]+)) {
location ~* /blogs/[^/]+/ressources/ {
auth_basic off;
}
set $auth "Restricted";
set $state "";
if ($request_method = "OPTIONS") {
# we are in options mode
set $state "O";
}
# if not in OPTIONS
if ($state = "O") {
set $auth off;
}
auth_basic $auth;
auth_basic_user_file $NGINX_FOLDER/$BLOGS_FOLDER/$username/.auth.allow;
if ($remote_user = "") {
# we are in anonymous mode
set $state "${state}A";
}
# if not in OPTIONS and not logged in
if ( $state = "A" ) {
add_header Www-Authenticate 'Basic realm="$auth"' always;
return 401;
}
if ($remote_user != $username) {
set $state "${state}D";
}
# if not in OPTIONS and folder diff from logged user
if ($state = "D") {
return 403;
}
dav_methods PUT DELETE MKCOL COPY MOVE;
dav_ext_methods PROPFIND OPTIONS;
dav_access user:rw group:rw all:r;
location ~* /blogs/[^/]+/password {
lua_need_request_body on;
add_header Content-Type "text/plain" always;
if ($request_method = "OPTIONS") {
return 200;
}
content_by_lua_block {
local password = ngx.req.get_body_data()
local handle = io.popen("echo -n '"..ngx.encode_base64(password).."' | base64 -d | openssl passwd -apr1 -stdin")
local result = handle:read("*a"):gsub('[\n\r]', '')
handle.close()
ngx.say(result)
}
}
}
}
}