{"componentChunkName":"component---src-templates-blog-post-js","path":"/blog/parsing-markdown-files-nginx","result":{"data":{"allGhostPost":{"edges":[{"node":{"title":"Parsing Markdown Files in Nginx","html":"

This is a really easy trick I found out to parse markdown files in Nginx.

\n

Example:

\n\n

The setup depends on PHP, which is what actually parses the markdown file and outputs the HTML.
\nThe whole thing is made out of two files:

\n\n\n

Once you get these two files:

\n
    \n
  1. Put them in a directory that has a recursive o+x (all its parents have o+x)
  2. \n
  3. Chown the files to you:you
  4. \n
  5. Chmod the files 664
  6. \n
\n

All that is left now is the Nginx configuration:

\n
location ~ \\.md$ {\n    try_files $uri =404;\n    fastcgi_pass    unix:/var/run/php5-fpm.sock;\n    fastcgi_param   DOCUMENT_ROOT    $document_root;\n    fastcgi_param   SCRIPT_NAME      $uri;\n    fastcgi_param   SCRIPT_FILENAME  /path/to/md.php;\n    include fastcgi_params;\n}\n\nlocation ~ ^(.*)\\.md/raw$ {\n    try_files $1.md =404;\n}\n
\n

And you are done! Rehash Nginx and voila!

\n","published_at":"2012-11-02T14:18:00.000+02:00","slug":"parsing-markdown-files-nginx","tags":[],"plaintext":"This is a really easy trick I found out to parse markdown files in Nginx.\n\nExample:\n\n * http://kamalnasser.net/dump/markdown.md\n * Source: http://kamalnasser.net/dump/markdown.md/raw\n\nThe setup depends on PHP, which is what actually parses the markdown file and\noutputs the HTML.\nThe whole thing is made out of two files:\n\n * markdown.php [http://michelf.ca/projects/php-markdown/] -- Markdown Parser\n * md.php [http://kamalnasser.net/dump/md.phps] -- Nginx Handler\n\nOnce you get these two files:\n\n 1. Put them in a directory that has a recursive o+x (all its parents have o+x)\n 2. Chown the files to you:you\n 3. Chmod the files 664\n\nAll that is left now is the Nginx configuration:\n\nlocation ~ \\.md$ {\n try_files $uri =404;\n fastcgi_pass unix:/var/run/php5-fpm.sock;\n fastcgi_param DOCUMENT_ROOT $document_root;\n fastcgi_param SCRIPT_NAME $uri;\n fastcgi_param SCRIPT_FILENAME /path/to/md.php;\n include fastcgi_params;\n}\n\nlocation ~ ^(.*)\\.md/raw$ {\n try_files $1.md =404;\n}\n\n\nAnd you are done! Rehash Nginx and voila!","meta_description":null}}]}},"pageContext":{"slug":"parsing-markdown-files-nginx","prev":null,"next":"duplicity-amazon-s3-backups"}},"staticQueryHashes":["3649515864"]}