§2023-06-04

  1. setup directory
alexlai@h2Jammy:~$ mkdir -p build/nginx-markdown && cd $_
alexlai@h2Jammy:~/build/nginx-markdown$ 
  1. Markdown filter Render markdown files as html on-the-fly
alexlai@h2Jammy:~/build/nginx-markdown$ git clone https://github.com/ukarim/ngx_markdown_filter_module
Cloning into 'ngx_markdown_filter_module'...
remote: Enumerating objects: 31, done.
remote: Counting objects: 100% (31/31), done.
remote: Compressing objects: 100% (22/22), done.
remote: Total 31 (delta 12), reused 28 (delta 9), pack-reused 0
Receiving objects: 100% (31/31), 7.98 KiB | 2.66 MiB/s, done.
Resolving deltas: 100% (12/12), done.
alexlai@h2Jammy:~/build/nginx-markdown$ ls -l
total 0
drwxrwxr-x 3 alexlai alexlai 143  六   4 15:30 ngx_markdown_filter_module
  1. Install required packages
alexlai@h2Jammy:~/build/nginx-markdown$ sudo apt -y install geoip-database cmark libcmark-dev  libpcre3 libpcre3-dev libgeoip-dev
  1. Get nginx source, configure, make and sudo make install
  • use 1.23.4 as released 28-Mar-2023 16:08
alexlai@h2Jammy:~/build/nginx-markdown$ mkdir src && cd $_
alexlai@h2Jammy:~/build/nginx-markdown/src$ wget http://nginx.org/download/nginx-1.25.0.tar.gz
$ cd ..
$ tar xvf src/nginx-1.25.0.tar.gz 
$ cd nginx-1.25.0/
./configure --add-module=../ngx_markdown_filter_module \
    --pid-path=/run/nginx.pid \
    --lock-path=/run/lock/nginx.lock \
    --user=www-data --group=www-data \
    --http-log-path=/var/log/nginx/access.log \
    --error-log-path=stderr \
    --http-client-body-temp-path=/var/lib/nginx/client-body \
    --http-proxy-temp-path=/var/lib/nginx/proxy \
    --http-fastcgi-temp-path=/var/lib/nginx/fastcgi \
    --http-scgi-temp-path=/var/lib/nginx/scgi \
    --http-uwsgi-temp-path=/var/lib/nginx/uwsgi \
    --with-compat \
    --with-debug \
    --with-file-aio \
    --with-http_addition_module \
    --with-http_auth_request_module \
    --with-http_dav_module  \
    --with-http_degradation_module \
    --with-http_flv_module \
    --with-http_geoip_module \
    --with-http_gunzip_module \
    --with-http_gzip_static_module \
    --with-http_mp4_module \
    --with-http_realip_module \
    --with-http_secure_link_module \
    --with-http_slice_module \
    --with-http_ssl_module \
    --with-http_stub_status_module \
    --with-http_sub_module \
    --with-http_v2_module \
    --with-mail \
    --with-mail_ssl_module \
    --with-pcre-jit \
    --with-stream \
    --with-stream_geoip_module \
    --with-stream_realip_module \
    --with-stream_ssl_module \
    --with-stream_ssl_preread_module \
    --with-threads 
    
    # --with-http_lua_module  <-- not supported
    # ./configure: error: invalid option "--with-http_lua_module"
    
  ...
 creating objs/Makefile

Configuration summary
  + using threads
  + using system PCRE library
  + using system OpenSSL library
  + 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: "/run/nginx.pid"
  nginx logs errors to stderr
  nginx http access log file: "/var/log/nginx/access.log"
  nginx http client request body temporary files: "/var/lib/nginx/client-body"
  nginx http proxy temporary files: "/var/lib/nginx/proxy"
  nginx http fastcgi temporary files: "/var/lib/nginx/fastcgi"
  nginx http uwsgi temporary files: "/var/lib/nginx/uwsgi"
  nginx http scgi temporary files: "/var/lib/nginx/scgi"
 
...
$ time make -j6
...
make[1]: Leaving directory '/home/alexlai/build/nginx-markdown/nginx-1.23.1'

real	0m28.374s
user	1m32.057s
sys	0m18.630s
alexlai@h2Jammy:~/build/nginx-markdown-01/nginx-1.25.0$ ./objs/nginx -version
nginx version: nginx/1.25.0

$ sudo make install
make -f objs/Makefile install
make[1]: Entering directory '/home/alexlai/build/nginx-markdown-01/nginx-1.25.0'
test -d '/usr/local/nginx' || mkdir -p '/usr/local/nginx'
test -d '/usr/local/nginx/sbin' \
	|| mkdir -p '/usr/local/nginx/sbin'
test ! -f '/usr/local/nginx/sbin/nginx' \
	|| mv '/usr/local/nginx/sbin/nginx' \
		'/usr/local/nginx/sbin/nginx.old'
cp objs/nginx '/usr/local/nginx/sbin/nginx'
test -d '/usr/local/nginx/conf' \
	|| mkdir -p '/usr/local/nginx/conf'
cp conf/koi-win '/usr/local/nginx/conf'
cp conf/koi-utf '/usr/local/nginx/conf'
cp conf/win-utf '/usr/local/nginx/conf'
test -f '/usr/local/nginx/conf/mime.types' \
	|| cp conf/mime.types '/usr/local/nginx/conf'
cp conf/mime.types '/usr/local/nginx/conf/mime.types.default'
test -f '/usr/local/nginx/conf/fastcgi_params' \
	|| cp conf/fastcgi_params '/usr/local/nginx/conf'
cp conf/fastcgi_params \
	'/usr/local/nginx/conf/fastcgi_params.default'
test -f '/usr/local/nginx/conf/fastcgi.conf' \
	|| cp conf/fastcgi.conf '/usr/local/nginx/conf'
cp conf/fastcgi.conf '/usr/local/nginx/conf/fastcgi.conf.default'
test -f '/usr/local/nginx/conf/uwsgi_params' \
	|| cp conf/uwsgi_params '/usr/local/nginx/conf'
cp conf/uwsgi_params \
	'/usr/local/nginx/conf/uwsgi_params.default'
test -f '/usr/local/nginx/conf/scgi_params' \
	|| cp conf/scgi_params '/usr/local/nginx/conf'
cp conf/scgi_params \
	'/usr/local/nginx/conf/scgi_params.default'
test -f '/usr/local/nginx/conf/nginx.conf' \
	|| cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf'
cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf.default'
test -d '/run' \
	|| mkdir -p '/run'
test -d '/var/log/nginx' \
	|| mkdir -p '/var/log/nginx'
test -d '/usr/local/nginx/html' \
	|| cp -R html '/usr/local/nginx'
make[1]: Leaving directory '/home/alexlai/build/nginx-markdown-01/nginx-1.25.0'
  1. create /var/lib/nginx/
$ sudo mkdir /var/lib/nginx <-- in ubuntu distribution, this dir exists

$ ls -l /var/lib/nginx/
total 0
drwx------  2 nobody root  6 十二 18 10:07 body
drwx------  2 nobody root  6 十二 18 08:00 fastcgi
drwx------ 12 nobody root 96 十二 18 17:56 proxy
drwx------  2 nobody root  6 十二 18 08:00 scgi
drwx------  2 nobody root  6 十二 18 08:00 uwsgi

$ sudo chown -R www-data:www-data /var/lib/nginx/
$ ls -l /var/lib/nginx/
total 0
drwx------  2 www-data www-data  6 十二 18 10:07 body
drwx------  2 www-data www-data  6 十二 18 08:00 fastcgi
drwx------ 12 www-data www-data 96 十二 18 17:56 proxy
drwx------  2 www-data www-data  6 十二 18 08:00 scgi
drwx------  2 www-data www-data  6 十二 18 08:00 uwsgi
  1. /etc/systemd/system/nginx.service
[Unit]
Description=A high performance web server and a reverse proxy server
After=network.target network-online.target nss-lookup.target

[Service]
Type=forking
PIDFile=/run/nginx.pid
PrivateDevices=yes
SyslogLevel=err

ExecStart=/usr/local/nginx/sbin/nginx -g 'pid /run/nginx.pid; error_log stderr;'
ExecReload=/usr/local/nginx/sbin/nginx -s reload
KillMode=mixed

[Install]
WantedBy=multi-user.target
  1. ignore .... ?? Change port 80 to 8888, /usr/local/nginx/conf ??
$ diff nginx.conf.ori nginx.conf
36c36
<         listen       80;
---
>         listen       8888;

6.1 cat /usr/local/nginx/conf/nginx.conf

#user  nobody;
worker_processes  1;

error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {
    worker_connections  2048; # original 1024
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    charset utf-8;

    # try to correct ngx_markdown_filter_module
    client_max_body_size 100M;
    # Set the buffer size for reading client request body
    client_body_buffer_size 10M;
    # Set the buffer size for reading from the upstream server
    proxy_buffer_size 64k;
    # Set the number and size of buffers used for reading from the upstream server
    proxy_buffers 8 64k;
    # Set the size of the buffer used for reading from the upstream server when the connection is busy
    proxy_busy_buffers_size 128k;
    # Set the timeout for reading from the upstream server
    proxy_read_timeout 300s;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       43888;
        # server_name  localhost;
        server_name h2Jammy.yushei.net;

        #charset koi8-r;
	charset utf-8;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
            autoindex on;
            autoindex_exact_size off;
            autoindex_localtime on;
        }

        # Render Markdown files as HTML pages using ngx_http_markdown_filter_module
        location ~ \.md$ {
            add_header Content-Type 'text/html';
            markdown_filter on;
            markdown_template /usr/local/nginx/html/template.html;
            # markdown_template html/template.html;
            # sub_filter_types *;
            # sub_filter '</body>' '<div style="padding: 20px;">$markdown$</div></body>';
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }


    }

}
  1. sudo systemctl start nginx.service, check http://h2Jammy.yushei.net:43888
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.
  1. Check available samba share
[alexlai@h2nas01 conf]$ smbclient -L munetaka.me
Password for [H2NAS01.YUSHEI.NET\alexlai]:

        Sharename       Type      Comment
        ---------       ----      -------
        homes           Disk      homes contains all users' home
        JupyterHub      Disk      JupyterHub Shared pholders
        MailPlus        Disk      Synology MailPlus
        pgAdmin4        Disk      pgAdmin4
        postgreSQL      Disk      
        web             Disk      System default shared folder
        web_packages    Disk      
        柯家新築案 Disk      
        IPC$            IPC       IPC Service ()
        home            Disk      Home directory of alexlai
SMB1 disabled -- no workgroup available
  1. Mount samaba drive
  • requiremnts
    • sudo apt install cifs-utils -y
    • `sudo apt install smbclient -y
  • create /home/alexlai/.smb as
user=alexlai
password=TxxxxYxxLxx#1nnn
```yaml 
- create mount point
```bash
$ sudo mkdir /opt/munetakaHyputerHub
$ sudo chown alexlai:alexlai /opt/munetakaHyputerHub/
  • /etc/fstab

# /dev/md10
UUID=82d1e232-2bdc-4e84-b202-44f9d0c63712       /               xfs             rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,sunit=1024,swidth=3072,noquota 0 1

# nas01.chingyen.com.tw:/volume1/YsUbuntuJupyterHubProj
#nas01.chingyen.com.tw:/volume1/YsUbuntuJupyterHubProj  /home/anaconda_user/JupyterHub-2020.07/notebook/ChingYenNas     nfs4            rw,vers=4.1,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=192.168.2.252,local_lock=none,addr=192.168.11.251  0 0

# nas01.chingyen.com.tw:/volume1/YsUbuntuJupyterHubProj
192.168.11.251:/volume1/YsUbuntuJupyterHubProj   /home/anaconda_user/JupyterHub-2020.07/notebook/ChingYenNas     nfs4            rw,vers=4.1,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=192.168.2.252,local_lock=none,addr=192.168.11.251  0 0

# nas01.chingyen.com.tw:/volume1/YsUbuntuJupyterHubProj   /home/anaconda_user/JupyterHub/notebook/ChingYenNas  nfs  _netdev,noauto,x-systemd.automount,x-systemd.mount-timeout=10,timeo=14,x-systemd.idle-timeout=1min 0 0

# /dev/sde2
UUID=3b797c75-8a8f-4a89-a392-a764003e4f9c       none            swap            defaults        0 0

# mount munetaka.me JupyterHub smb share
//munetaka.me/JupyterHub    /opt/munetakaJupyterHub        cifs    uid=0,credentials=/home/alexlai/.smb,iocharset=utf8,noperm 0 0
  1. Japanes fonts
$ sudo pacman -S noto-fonts-cjk noto-fonts-emoji noto-fonts
$ fc-list :lang=ja
....

  1. List Directory
$ diff nginx.conf.ori nginx.conf
20a21
>     charset utf-8;
36c37
<         listen       80;
---
>         listen       8888;
45a47,49
>             autoindex on;
>             autoindex_exact_size off;
>             autoindex_localtime on;
  1. Disaply markdown file
# Render Markdown files as HTML pages using ngx_http_markdown_filter_module
        location ~ \.md$ {
            add_header Content-Type 'text/html';
            markdown_filter on;
            sub_filter_types *;
#            sub_filter '</body>' '<div style="padding: 20px;">$markdown$</div></body>';
        }
  1. add /usr/local/nginx/html.template.html
<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title></title>
  <style>
    #root {
      font-family: sans-serif;
      font-size: 18px;
      color: #323232;
      margin: 0 auto;
      max-width: 768px;
    }
  </style>
</head>
<body>

  <div id="root">
    {{content}}
  </div>

  <script>
    (function() {
      // try to set document title
      var l = ['h1', 'h2', 'h3'];
      for (var i = 0; i < l.length; i++) {
        var h = document.getElementsByTagName(l[i]);
        if (h.length > 0) {
          document.title = h[0].innerText;
          break;
        }
      }
    })();
  </script>

</body>
</html>
  • 2023-04-11 nginx.conf
#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    charset utf-8;
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       8888;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
            autoindex on;
            autoindex_exact_size off;
            autoindex_localtime on;
        }

        # Render Markdown files as HTML pages using ngx_http_markdown_filter_module
        location ~ \.md$ {
            add_header Content-Type 'text/html';
            markdown_filter on;
            sub_filter_types *;
            # sub_filter '</body>' '<div style="padding: 20px;">$markdown$</div></body>';
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}
Return to Top