-
Notifications
You must be signed in to change notification settings - Fork 3
/
nginx-explorer.conf
127 lines (103 loc) · 3.53 KB
/
nginx-explorer.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
# some options from https://github.com/h5bp/server-configs-nginx/tree/main
gzip on;
gzip_comp_level 5;
gzip_min_length 256;
gzip_proxied any;
gzip_vary on;
gzip_types text/javascript text/plain application/javascript application/x-javascript;
open_file_cache max=1000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
sendfile on;
sendfile_max_chunk 2m;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
# include mime.types;
types {
video/x-matroska mkv;
}
add_header X-Content-Type-Options nosniff always;
add_header X-Frame-Options SAMEORIGIN always;
server_tokens off;
charset UTF-8;
charset_types text/css text/plain text/vnd.wap.wml text/javascript text/markdown application/json application/manifest+json;
map $host $ng_expl_html {
default "<!DOCTYPE html><html><script name='NgxEx' favicon='🗃️' upload='/_ngx_expl/upload/' upload-max-size='209715200' icons='/_ngx_expl/icons/' src='/_ngx_expl/main.js'></script>";
}
# a file download will not end with a '/'
# so here we make sure we only replace '<html>'
# for actual file listing
map $uri $cond_filter {
~/$ $ng_expl_html;
default "<html>";
}
server {
# Listen on http port
listen 8080;
# Serve files listing
location / {
# Path to serve
root /home/user/downloads;
sub_filter_once on;
sub_filter "<html>" $cond_filter;
add_header Access-Control-Expose-Headers 'Content-Length';
add_header Access-Control-Expose-Headers 'Content-Disposition';
# Random id so nginx doesn't serve random html files
# that browsers would render, you can remove this line
# if you want directories with index.html to be rendered
index 953b12d3-5ab2-49ad-8f49-6ea27f3a9994;
# File listing (index) in html format
autoindex on;
autoindex_format html;
autoindex_exact_size on;
# Auth
auth_basic "Private files";
auth_delay 1s;
auth_basic_user_file /basic_auth/download.htpasswd;
error_page 401 = @unprompt; # prevent browser prompt
}
location @unprompt {
## override content-type ##
types { } default_type "text/html; charset=utf-8";
return 403 $ng_expl_html;
}
# this is where app files (main.js, icons) are,
# drawback is that a folder named '_ngx_expl' cannot be indexed
location ^~ /_ngx_expl/ {
alias /var/www/ngx_expl/;
}
# Upload location
location ^~ /_ngx_expl/upload/ {
limit_except GET POST {
deny all;
}
# Where to store the files on disk
client_body_temp_path /home/user/uploads/;
# Store the file on disk, and don't delete it, no matter
# what the proxy returns.
client_body_in_file_only on;
client_body_buffer_size 16m;
client_max_body_size 256m;
# Give the client 2h to upload.
client_body_timeout 2h;
# Now proxy to the small internal server we started
# below, and don't pass the uploaded file to it.
proxy_set_body off;
proxy_pass http://127.0.0.1:4000/$request_method;
auth_basic "Upload files";
auth_delay 1s;
auth_basic_user_file /basic_auth/upload.htpasswd;
}
}
# Dummy server that return 200 to finish files upload
server {
listen 127.0.0.1:4000;
location /POST {
return 204;
}
location /GET {
return 200;
}
}