§2023-04-09

To serve Markdown files using Nginx, you can use a third-party module like nginx-markdown-module. This module provides the ability to parse Markdown files on the fly and serve them as HTML.

cd nginx-1.20.1
./configure --add-module=/path/to/nginx-markdown-module

以上: by ChatGPT

試作機器: hc4nas02.yushei.net

  1. git clone
$ git clone https://github.com/jbfavre/ngx-markdown-module.git
apt-get source nginx
apt-get build-dep nginx
  1. Get nginx source
$ tar xvf src/nginx-1.23.4.tar.gz
$ cd nginx-1.23.4/
$ CFLAGS=-Wno-error ./configure --add-module=../ngx-markdown-module/ngx-md-filter-module \
    --add-module=../ngx-markdown-module/ngx-md-handler-module
...
creating objs/Makefile

Configuration summary
  + using system PCRE2 library
  + OpenSSL library is not used
  + using system zlib library

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx modules path: "/usr/local/nginx/modules"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"


1.  gli clone

```bash
alexlai@hc4nas02:~/build$ git clone git@github.com:evanmiller/nginx-markdown-module.git
  1. sudo apt-get install libmarkdown2-dev

  2. Get nginx source,

$ wget http://nginx.org/download/nginx-1.22.1.tar.gz
$ cd ..
$ tar xvf src/nginx-1.22.1.tar.gz 
$ $ cd nginx-1.22.1/
$ ./configure --add-module=../nginx-markdown-module
...
creating objs/Makefile

Configuration summary
  + using system PCRE2 library
  + OpenSSL library is not used
  + using system zlib library

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx modules path: "/usr/local/nginx/modules"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"
 
 $ time  make -j 6
 ... 
 ../nginx-markdown-module/ngx_http_markdown_module.c:108:10: error: ‘out.buf’ is used uninitialized in this function [-Werror=uninitialized]
  108 |     buf  = out.buf;
      |     ~~~~~^~~~~~~~~
cc1: all warnings being treated as errors
make[1]: *** [objs/Makefile:1203: objs/addon/nginx-markdown-module/ngx_http_markdown_module.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make[1]: Leaving directory '/home/alexlai/build/nginx-1.22.1'
make: *** [Makefile:10: build] Error 2
$ wget http://nginx.org/download/nginx-1.23.4.tar.gz
$ cd ..
$ tar xvf src/nginx-1.23.4.tar.gz 
$ cd nginx-1.23.4/
$ ./configure --add-module=../nginx-markdown-module
...

Configuration summary
  + using system PCRE2 library
  + OpenSSL library is not used
  + using system zlib library

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx modules path: "/usr/local/nginx/modules"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"
$ time make
make[1]: *** [objs/Makefile:1204: objs/addon/nginx-markdown-module/ngx_http_markdown_module.o] Error 1
make[1]: Leaving directory '/home/alexlai/build/nginx-1.23.4'
make: *** [Makefile:10: build] Error 2

real    1m34.981s
user    1m28.557s
sys     0m10.291s



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

---

- Look for the `--with-http_md_module` option in the output. If you see this option, it means that Nginx was compiled with the ngx_http_markdown_module.

```bash
$ nginx -V > test
nginx version: nginx/1.18.0 (Ubuntu)
built with OpenSSL 1.1.1f  31 Mar 2020
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -fdebug-prefix-map=/build/nginx-qv2Nx5/nginx-1.18.0=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fPIC' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-compat --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --with-http_addition_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_xslt_module=dynamic --with-stream=dynamic --with-stream_ssl_module --with-mail=dynamic --with-mail_ssl_module