This is a really easy trick I found out to parse markdown files in Nginx.
Example:
The setup depends on PHP, which is what actually parses the markdown file and outputs the HTML.
The whole thing is made out of two files:
- markdown.php -- Markdown Parser
- md.php -- Nginx Handler
Once you get these two files:
- Put them in a directory that has a recursive o+x (all its parents have o+x)
- Chown the files to you:you
- Chmod the files 664
All that is left now is the Nginx configuration:
location ~ \.md$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SCRIPT_NAME $uri;
fastcgi_param SCRIPT_FILENAME /path/to/md.php;
include fastcgi_params;
}
location ~ ^(.*)\.md/raw$ {
try_files $1.md =404;
}
And you are done! Rehash Nginx and voila!