# A dynamic web-site written wholly in nginx.conf? Introducing mdoc.su!

**URL:** <https://www.ruby-forum.com/t/a-dynamic-web-site-written-wholly-in-nginx-conf-introducing-mdoc-su/226681>\
**Category:** NGINX\
**Created:** [February 18, 2013, 9:06am UTC](https://www.ruby-forum.com/t/a-dynamic-web-site-written-wholly-in-nginx-conf-introducing-mdoc-su/226681 "2013-02-18T09:06:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Constantine\_ASMure](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/3ec8ea/32.png) [@Constantine\_ASMure](https://www.ruby-forum.com/u/Constantine_ASMure)\
**Post date:** [February 18, 2013, 9:06am UTC](https://www.ruby-forum.com/t/a-dynamic-web-site-written-wholly-in-nginx-conf-introducing-mdoc-su/226681/1 "2013-02-18T09:06:51Z")

</div>

This is a multi-part message in MIME format.  
--------------030707040502000103070707  
Content-Type: text/plain; charset=KOI8-R; format=flowed  
Content-Transfer-Encoding: 7bit

Dear nginx@,

I’m not sure if this has already been done before and to what extent,  
but I’d like to demonstrate that a whole web-service “portal” can be  
written exclusively in nginx.conf, without any php, perl, python, java  
or cgi, or even any files external to nginx.conf.

Introducing [http://mdoc.su/](http://mdoc.su/) .

The service provides deterministic URL tinyfication / URI shortening for  
BSD manual pages.

How does it work?

It operates on 3 inputs: the operating system, the section and the  
manual page.

For example, to see the kqueue(2) manual page from FreeBSD, you can  
point your browser to [kqueue](http://mdoc.su/f/kqueue) , or mdoc.su/f/kqueue.2,  
or mdoc.su/f/2/kqueue, or you can even use “FreeBSD” or “freebsd” in  
place of “f”, as in, [kqueue](http://mdoc.su/freebsd/kqueue) etc.

When nginx receives the request, it quickly gets re-written, and a  
redirect to [FreeBSD Manual Pages](http://FreeBSD.org/cgi/man.cgi) is produced.

Same for OpenBSD, NetBSD and DragonFly BSD, of course.

Forgot how to specify timeouts for ssh(1)? [http://mdoc.su/o/ssh](http://mdoc.su/o/ssh)

The site even has a start page, also exclusively through nginx.conf, and  
supports Google Webmaster Tools site verification, through the “HTML  
file upload” option, through nginx.conf (of course!). (BTW, the format  
of those verification files has changed a couple of years back, where  
special and unique file content is now required, and the new file format  
itself is a very-very big secret, that Google will not share with anyone  
without a file-save-capable browser or an NDA! Reverse-engineered with  
nginx.conf, too!)

Notice that the whole ordeal runs entirely out of nginx and is  
controlled by an nginx.conf file, which I think is pretty nifty. 🙂

The source code is available at [GitHub - cnst/mdoc.su: Deterministic URL shortener for BSD manual pages, written in nginx.conf](https://github.com/cnst/mdoc.su) , and  
might also be attached inline to this message.

Comments, questions and suggestions are very welcome.

Best regards,  
Constantine.

--------------030707040502000103070707  
Content-Type: text/plain; charset=KOI8-R;  
name=“mdoc.su.nginx.conf”  
Content-Transfer-Encoding: 7bit  
Content-Disposition: inline;  
filename=“mdoc.su.nginx.conf”

# cnst: mdoc.su.nginx.conf, 2013-02-14/17

# Deterministic URL shortener for BSD manual pages, written in

nginx.conf

# Copyright (c) 2013 Constantine A. Murenin [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

# [http://mdoc.su/](http://mdoc.su/)

# [GitHub - cnst/mdoc.su: Deterministic URL shortener for BSD manual pages, written in nginx.conf](https://github.com/cnst/mdoc.su)

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 = / {  
default\_type text/html;  
return 200  
"\<?xml version='1.0' encoding='utf-8'?\>

mdoc.su — Manual Pages for FreeBSD, OpenBSD, NetBSD and DragonFly BSD!

# mdoc.su

## man pages for FreeBSD, NetBSD, OpenBSD and DragonFly

* * *

```
Usage: **mdoc.su/b/p** or **mdoc.su/b/0/p** or **mdoc.su/b/p.0** , where
    b is
      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:  
[http://mdoc.su/f/mdoc](http://mdoc.su/f/mdoc) —  
according to FreeBSD  
[http://mdoc.su/n/mdoc](http://mdoc.su/n/mdoc) —  
according to NetBSD  
[http://mdoc.su/o/mdoc](http://mdoc.su/o/mdoc) —  
according to OpenBSD  
[http://mdoc.su/d/mdoc](http://mdoc.su/d/mdoc) —  
according to DragonFly

Or, if you will,  
[http://mdoc.su/f/mdoc.7](http://mdoc.su/f/mdoc.7)  
[http://mdoc.su/f/7/mdoc](http://mdoc.su/f/7/mdoc)
```

* * *

© 2013 Constantine A. Murenin (cnst)

* * *

nginx/$nginx\_version at $host

"; } location = /google2a7d1d40a6b37a23.html { rewrite ^/(.\*) $1; return 200 "google-site-verification: $uri"; } location /FreeBSD { rewrite ^/FreeBSD(/.\*)?$ /f$1; } location /f { set $fb "http://www.freebsd.org/cgi/man.cgi?query="; set $fs "&sektion="; rewrite ^/freebsd(/.\*)?$ /.$1; rewrite ^/./([^/.]+)/([^/]+)$ $fb$2$fs$1 redirect; rewrite ^/./([^/]+)\.([1-9])$ $fb$1$fs$2 redirect; rewrite ^/./([^/]+)$ $fb$1$fs redirect; rewrite ^/./?$ / last; return 404; } location /NetBSD { rewrite ^/NetBSD(/.\*)?$ /n$1; } location /n { set $nb "http://netbsd.gw.com/cgi-bin/man-cgi?"; rewrite ^/netbsd(/.\*)?$ /.$1; rewrite ^/./([a-z]+[0-9]\*[kx]?)/([^/]+)/([^/]+)$ $nb$3+$2.$1 redirect; rewrite ^/./([^/]+)/([^/]+)$ $nb$2+$1 redirect; rewrite ^/./([^/]+)\.([1-9]\.[a-z]+[0-9]\*[kx]?)$ $nb$1+$2 redirect; rewrite ^/./([^/]+)\.([1-9])$ $nb$1+$2 redirect; rewrite ^/./([^/]+)$ $nb$1 redirect; rewrite ^/./?$ / last; return 404; } location /OpenBSD { rewrite ^/OpenBSD(/.\*)?$ /o$1; } location /o { set $ob "http://www.openbsd.org/cgi-bin/man.cgi?query="; set $os "&sektion="; rewrite ^/openbsd(/.\*)?$ /.$1; rewrite ^/./([a-z]+[0-9]\*[k]?)/([1-9]|3p)/([^/]+)$ $ob$3$os$2&arch=$1 redirect; rewrite ^/./([^/.]+)/([^/]+)$ $ob$2$os$1 redirect; rewrite ^/./([^/]+)\.([1-9]|3p)\.([a-z]+[0-9]\*[k]?)$ $ob$1$os$2&arch=$3 redirect; rewrite ^/./([^/]+)\.([1-9]|3p)$ $ob$1$os$2 redirect; rewrite ^/./([^/]+)$ $ob$1$os redirect; rewrite ^/./?$ / last; return 404; } location /DragonFly { rewrite ^/DragonFly(BSD)?(/.\*)?$ /d$2; } location /d { set $db "http://leaf.dragonflybsd.org/cgi/web-man?command="; set $ds "&section="; rewrite ^/dragonfly(bsd)?(/.\*)?$ /d$2; rewrite ^/d(ragon)?fly(/.\*)?$ /d$2; rewrite ^/./([^/.]+)/([^/]+)$ $db$2$ds$1 redirect; rewrite ^/./([^/]+)\.([1-9])$ $db$1$ds$2 redirect; rewrite ^/./([^/]+)$ $db$1$ds redirect; rewrite ^/./?$ / last; return 404; } location / { return 403; } access\_log logs/mdoc.su/mdoc.su.access.log combined; error\_log logs/mdoc.su/mdoc.su.error.log warn; }

--------------030707040502000103070707–
