Build memo for nginx open source from source with specific modules

# Build memo for nginx open source from source with specific modules

## System
```
# cat /etc/os-release
PRETTY_NAME="Ubuntu 24.04 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04 LTS (Noble Numbat)"
(snip)
```

## Refs

- Compiling and Installing from Source

https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-open-source/#sources

https://nginx.org/en/docs/configure.html

## Check dependencies
```
# apt list --installed | grep -i pcre2*dev
# apt list --installed | grep -i ^zlib1g-dev
# apt list --installed | grep -i ^libssl-dev
```
```
# apt-cache search . | grep -Ei pcre2.*dev.*
libpcre2-dev - New Perl Compatible Regular Expression Library - development files
libpcre2-ocaml-dev - OCaml bindings for PCRE2 (Perl Compatible Regular Expression)
librust-grep-pcre2-dev - Use PCRE2 with the 'grep' crate - Rust source code
librust-pcre2-dev - High level wrapper library for PCRE2 - Rust source code
librust-pcre2-sys-dev - Low level bindings to PCRE2 - Rust source code
lua-rex-pcre2-dev - PCRE2 development files for the Lua language
```

## Install depemdencies lacked
```
# apt -y install libpcre2-dev
# apt -y install zlib1g-dev
# apt -y install libssl-dev
```

## Check stable version namber

https://nginx.org/en/download.html

## Download source
```
# wget https://nginx.org/download/nginx-1.26.0.tar.gz
# tar zxf nginx-1.26.0.tar.gz
```
## Simple build test
```
# cd nginx-1.26.0/
~/nginx-1.26.0# ./configure

(snip)
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
~/nginx-1.26.0#
```
```
~/nginx-1.26.0# make
~/nginx-1.26.0# make install
```
If no problems, clean
```
~/nginx-1.26.0# make clean
rm -rf Makefile objs
```

## Build with several options
```
~/nginx-1.26.0# ./configure --with-stream --with-http_ssl_module

(snip)
Configuration summary
  + using system PCRE2 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: "/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"
```

- With nginx-sticky-module-ng
    - https://bitbucket.org/nginx-goodies/nginx-sticky-module-ng/branch/master
- Before build, you may need this workaround
    - https://github.com/Refinitiv/nginx-sticky-module-ng/issues/9#issuecomment-1186386080

```
   206          /* check weather a cookie is present or not and save it */
   207          /* if (ngx_http_parse_multi_header_lines(&r->headers_in.cookies, &iphp->sticky_conf->cookie_name, &route) != NGX_DECLINED) { */
   208          if (ngx_http_parse_multi_header_lines(r, r->headers_in.cookie, &iphp->sticky_conf->cookie_name, &route) != NULL) {
```

```
~/nginx-1.26.0# ./configure --with-stream --with-http_ssl_module --add-module=/root/nginx-goodies-nginx-sticky-module-ng-08a395c66e42

(snip)
adding module in /root/nginx-goodies-nginx-sticky-module-ng-08a395c66e42
 + ngx_http_sticky_module was configured
checking for PCRE2 library ... found
checking for OpenSSL library ... found
checking for zlib library ... found
creating objs/Makefile

Configuration summary
  + using system PCRE2 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: "/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"
```

- Other configuration trials...
```
./configure \
--with-stream \
--with-http_ssl_module \
--add-module=/root/nginx-goodies-nginx-sticky-module-ng-08a395c66e42 \
--conf-path=/etc/nginx/nginx.conf
```
```
# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.26.0
built by gcc 13.2.0 (Ubuntu 13.2.0-23ubuntu4)
built with OpenSSL 3.0.13 30 Jan 2024
TLS SNI support enabled
configure arguments: --with-stream --with-http_ssl_module --add-module=/root/nginx-goodies-nginx-sticky-module-ng-08a395c66e42 --conf-path=/etc/nginx/nginx.conf
```

## After installation

https://nginx.org/en/docs/beginners_guide.html

https://nginx.org/en/docs/switches.html

### stop start etc
```
# /usr/local/nginx/sbin/nginx -s quit
# /usr/local/nginx/sbin/nginx -s reload
```
### verify
```
# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
```