-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmdoc.su.nginx.conf
269 lines (267 loc) · 9.21 KB
/
mdoc.su.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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#!/usr/sbin/nginx
# cnst: mdoc.su.nginx.conf, 2013-02-14/23
# Deterministic URL shortener for BSD manual pages, written in nginx.conf
# Author: Constantine A. Murenin (cnst)
# http://mdoc.su/ -- short manual page URLs
# http://nginx.conf.mdoc.su/mdoc.su.nginx.conf
# https://github.com/cnst/mdoc.su
# https://bitbucket.org/cnst/mdoc.su
############################################################################
#
# Copyright (c) 2013 Constantine A. Murenin <[email protected]>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
############################################################################
server {
listen *:80;
listen [::]:80;
server_name
mdoc.su
www.mdoc.su
*.mdoc.su;
if ($host != "mdoc.su") {
rewrite ^ http://mdoc.su$request_uri? redirect;
}
location = / {
if ($args ~ ^/) { rewrite ^ /-$args last; }
default_type text/html;
return 200
"<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en-CA' lang='en-CA'>
<head>
<title>mdoc.su — Manual Pages for FreeBSD, OpenBSD, NetBSD and DragonFly BSD!</title>
<meta name='description' content='Deterministic URL shortener for BSD manual pages, written in nginx.conf'/>
<meta name='keywords' content='short manual page URLs, man, URL, BSD UNIX'/>
</head>
<body>
<div style='text-align: center;'>
<h1 style='margin: 4pt auto; color: navy;'>mdoc.su</h1>
<h2 style='margin: 4pt auto;'>man pages for FreeBSD, NetBSD, OpenBSD and DragonFly</h2>
<hr style='width: 48em; font-family: monospace; border: none; border-top: 1px solid navy;'/>
<pre style='margin: 0 auto; width: 48em; font-family: monospace; text-align: left;'>Usage:
<strong>mdoc.su/b/p</strong>
<strong>mdoc.su/b/p.0</strong>
<strong>mdoc.su/b/0/p</strong>
where
b is -, or
f|n|o|d, or
FreeBSD|NetBSD|OpenBSD|DragonFly, or
same lower case , and
p is the name of the manual page, and
0 is the section number.
Now, what's mdoc?
See:
<a href='http://mdoc.su/f/mdoc'>http://mdoc.su/f/mdoc</a> — according to FreeBSD
<a href='http://mdoc.su/n/mdoc'>http://mdoc.su/n/mdoc</a> — according to NetBSD
<a href='http://mdoc.su/o/mdoc'>http://mdoc.su/o/mdoc</a> — according to OpenBSD
<a href='http://mdoc.su/d/mdoc'>http://mdoc.su/d/mdoc</a> — according to DragonFly
Or, if you will,
<a href='http://mdoc.su/-/mdoc.7'>http://mdoc.su/-/mdoc.7</a>
<a href='http://mdoc.su/-/7/mdoc'>http://mdoc.su/-/7/mdoc</a>
</pre>
<hr style='width: 48em; font-family: monospace; border: none; border-top: 1px solid darkred;'/>
<p><small>
© 2013 Constantine A. Murenin (cnst)
<br/>
<a href='http://nginx.conf.mdoc.su/mdoc.su.nginx.conf'>nginx.conf</a> |
<a href='https://github.com/cnst/mdoc.su' rel='nofollow'>github</a> |
<a href='https://bitbucket.org/cnst/mdoc.su' rel='nofollow'>bitbucket</a>
</small></p>
<hr/>
<p>nginx/$nginx_version at $host</p>
</div>
</body>
</html>";
}
location = /google2a7d1d40a6b37a23.html {
rewrite ^/(.*) $1;
return 200 "google-site-verification: $uri";
}
location ^~ /FreeBSD {
rewrite "^/FreeBSD([ ,-/].*)?$" /freebsd$1 last;
return 404;
}
location ^~ /f {
set $fb "http://www.freebsd.org/cgi/man.cgi?query=";
set $fs "&sektion=";
rewrite ^/f([4-9]|1[0-9])([0-9])([,/].*)?$ /freebsd-$1.$2$3;
rewrite "^/freebsd[ -/](?<fr>[0-9]+(\.[0-9]+)+)([,/].*)?$" /.$3;
rewrite ^/freebsd([,/].*)?$ /.$1;
rewrite ^/(?<bf>.)(?<b>,)(.*)$ /$3 last;
if ($b) {
rewrite ^/(?<bf>.)(/.*)$ /-$2 last;
}
if ($fr) {
set $fr "&manpath=FreeBSD+$fr-RELEASE";
}
rewrite ^/./([^/.]+)/([^/]+)$ $fb$2$fs$1$fr redirect;
rewrite ^/./([^/]+)\.([1-9])$ $fb$1$fs$2$fr redirect;
rewrite ^/./([^/]+)$ $fb$1$fs$fr redirect;
rewrite ^/./?$ / last;
return 410;
}
location ^~ /NetBSD {
rewrite "^/NetBSD([ ,-/].*)?$" /netbsd$1 last;
return 404;
}
location ^~ /n {
set $nb "http://netbsd.gw.com/cgi-bin/man-cgi?";
rewrite ^/n([3-9])([0-9])([,/].*)?$ /netbsd-$1.$2$3;
rewrite "^/netbsd[ -/](?<nr>[0-9]+(\.[0-9]+)+)([,/].*)?$" /.$3;
rewrite ^/netbsd([,/].*)?$ /.$1;
rewrite ^/(?<bn>.)(?<b>,)(.*)$ /$3 last;
if ($b) {
rewrite ^/(?<bn>.)(/.*)$ /-$2 last;
}
if ($nr) {
set $nr "+NetBSD-$nr";
}
rewrite ^/./([a-z]+[0-9]*[kx]?)/([^/]+)/([^/]+)$ $nb$3+$2.$1$nr redirect;
rewrite ^/./([^/]+)/([^/]+)$ $nb$2+$1$nr redirect;
rewrite ^/./([^/]+)\.([1-9]\.[a-z]+[0-9]*[kx]?)$ $nb$1+$2$nr redirect;
rewrite ^/./([^/]+)\.([1-9])$ $nb$1+$2$nr redirect;
rewrite ^/./([^/]+)$ $nb$1+$nr redirect;
rewrite ^/./?$ / last;
return 410;
}
location ^~ /OpenBSD {
rewrite "^/OpenBSD([ ,-/].*)?$" /openbsd$1 last;
return 404;
}
location ^~ /o {
set $ob "http://www.openbsd.org/cgi-bin/man.cgi?query=";
set $os "&sektion=";
rewrite ^/o([2-9])([0-9])([,/].*)?$ /openbsd-$1.$2$3;
rewrite "^/openbsd[ -/](?<or>[0-9]+(\.[0-9]+))([,/].*)?$" /.$3;
rewrite ^/openbsd([,/].*)?$ /.$1;
rewrite ^/(?<bo>.)(?<b>,)(.*)$ /$3 last;
if ($b) {
rewrite ^/(?<bo>.)(/.*)$ /-$2 last;
}
if ($or) {
set $or "&manpath=OpenBSD+$or";
}
rewrite ^/./([a-z]+[0-9]*[k]?)/([1-9]|3p)/([^/]+)$ $ob$3$os$2$or&arch=$1 redirect;
rewrite ^/./([^/.]+)/([^/]+)$ $ob$2$os$1$or redirect;
rewrite ^/./([^/]+)\.([1-9]|3p)\.([a-z]+[0-9]*[k]?)$ $ob$1$os$2$or&arch=$3 redirect;
rewrite ^/./([^/]+)\.([1-9]|3p)$ $ob$1$os$2$or redirect;
rewrite ^/./([^/]+)$ $ob$1$os$or redirect;
rewrite ^/./?$ / last;
return 410;
}
location ^~ /DragonFly {
rewrite ^/DragonFly(BSD)?([,/].*)?$ /d$2 last;
return 404;
}
location ^~ /d {
set $db "http://leaf.dragonflybsd.org/cgi/web-man?command=";
set $ds "§ion=";
rewrite ^/dragonfly(bsd)?([,/].*)?$ /d$2;
rewrite ^/d(ragon)?fly([,/].*)?$ /d$2;
rewrite ^/(?<bd>.)(?<b>,)(.*)$ /$3 last;
if ($b) {
rewrite ^/(?<bd>.)(/.*)$ /-$2 last;
}
rewrite ^/./([^/.]+)/([^/]+)$ $db$2$ds$1 redirect;
rewrite ^/./([^/]+)\.([1-9])$ $db$1$ds$2 redirect;
rewrite ^/./([^/]+)$ $db$1$ds redirect;
rewrite ^/./?$ / last;
return 410;
}
error_page 410 = @410;
location @410 {
rewrite "^/[a-z]{2,}\.?[1-9]?$" /-$uri last;
rewrite "^/[fnod]{2,4}/" @$uri last;
return 404;
}
location ~ "^/[a-z]{2,}\.?[1-9]?$" {
rewrite ^ /-$uri;
}
location ~ "^@/[fnod]{2,4}/" {
internal;
rewrite ^@(.+) $1;
set $b ,;
rewrite ^/([^/]*)(?<bf>f)(.*) /$1$3;
rewrite ^/([^/]*)(?<bn>n)(.*) /$1$3;
rewrite ^/([^/]*)(?<bo>o)(.*) /$1$3;
rewrite ^/([^/]*)(?<bd>d)(.*) /$1$3;
rewrite ^/(/.*)$ /-$1 last;
return 403;
}
# location /./ doesn't actually work, paths must be are assumed;
# [#%?] are out, too; but /?/ is supported in "location = /"
location ~ ^/[*+,.:_|~]/ { rewrite ^/.(.*)$ /-$1; }
location ^~ /-/ {
rewrite ^/./$ / last;
rewrite "^/.((/[-.0-9:A-Z_a-z]+){1,3})$" $1;
if ($uri ~ ^/-/) { return 404; }
rewrite ^/(.*) $1;
default_type text/html;
if ($b != ",") {
set $bf f;
set $bn n;
set $bo o;
set $bd d;
}
set $ul "";
if ($fr) { set $fr " $fr"; }
if ($nr) { set $nr " $nr"; }
if ($or) { set $or " $or"; }
if ($bf) {
set $ul
"$ul<li style='margin: 8pt;'><a href='/FreeBSD$fr/$uri'>FreeBSD$fr</a></li>\n";
}
if ($bn) {
set $ul
"$ul<li style='margin: 8pt;'><a href='/NetBSD$nr/$uri'>NetBSD$nr</a></li>\n";
}
if ($bo) {
set $ul
"$ul<li style='margin: 8pt;'><a href='/OpenBSD$or/$uri'>OpenBSD$or</a></li>\n";
}
if ($bd) {
set $ul
"$ul<li style='margin: 8pt;'><a href='/DragonFly/$uri'>DragonFly</a></li>\n";
}
return 300
"<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en-CA' lang='en-CA'>
<head>
<title>300 – Multiple Choices for $uri ∴ mdoc.su — short man-page URLs</title>
</head>
<body>
<div style='text-align: center;'>
<h1 style='margin: 4pt auto; color: navy;'><a href='http://mdoc.su/'
style='text-decoration: none; color: navy;'>mdoc.su</a></h1>
<hr style='width: 48em; font-family: monospace; border: none; border-top: 1px solid navy;'/>
<h2 style='margin: 4pt auto;'><small>$server_protocol</small> 300 — Multiple Choices</h2>
<h3 style='margin: 4pt auto;'>Which <big><strong><tt>$uri</tt></strong></big> is required?</h3>
<ul style='list-style: none; padding: 0;'>
$ul</ul>
<hr style='width: 48em; font-family: monospace; border: none; border-top: 1px solid darkred;'/>
<p><small>© 2013 Constantine A. Murenin (cnst)</small></p>
<hr/>
<p>nginx/$nginx_version at $host</p>
</div>
</body>
</html>";
}
location / { return 403; }
access_log logs/mdoc.su/mdoc.su.access.log combined;
error_log logs/mdoc.su/mdoc.su.error.log warn;
}