Build and install nchan as dynamic module on Ubuntu
Hello,
Please bear with me as I'm very new to this, so I will try to explain everything in details:
-
I tried to install the latest nginx from source (1.19.2) following this guide: https://devopscraft.com/how-to-compile-nginx-from-source-on-ubuntu-20-04/ (I use Ubuntu 20.04 LTS on my test server)
-
I tried to create the dynamic module for nchan following this guide: https://www.nginx.com/blog/compiling-dynamic-modules-nginx-plus/
My exact code for this step looks like this:
#!/bin/sh
NGINX_VERSION="1.19.2"
PCRE_VERSION="8.44"
ZLIB_VERSION="1.2.11"
OPENSSL_VERSION="1.1.1g"
NCHAN_VERSION="0.97"
curl https://codeload.github.com/slact/nchan/tar.gz/v${NCHAN_VERSION} | tar xz
wget https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz && tar zxvf nginx-${NGINX_VERSION}.tar.gz
# PCRE
wget https://ftp.pcre.org/pub/pcre/pcre-${PCRE_VERSION}.tar.gz && tar xzvf pcre-${PCRE_VERSION}.tar.gz
# zlib
wget https://www.zlib.net/zlib-${ZLIB_VERSION}.tar.gz && tar xzvf zlib-${ZLIB_VERSION}.tar.gz
# OpenSSL
wget https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz && tar xzvf openssl-${OPENSSL_VERSION}.tar.gz
# Clean up all .tar.gz files
rm -rf *.tar.gz
cd nginx-${NGINX_VERSION}
sudo ./configure --with-compat \
--user=nginx \
--group=nginx \
--modules-path=/usr/lib/nginx/modules \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--with-pcre=../pcre-${PCRE_VERSION} \
--with-pcre-jit \
--with-zlib=../zlib-${ZLIB_VERSION} \
--with-openssl=../openssl-${OPENSSL_VERSION} \
--with-openssl-opt=no-nextprotoneg \
--with-debug
--add-dynamic-module=../nchan-${NCHAN_VERSION}
make
make modules
The output of the make modules looks like this;
make -f objs/Makefile modules
make[1]: Entering directory '/root/nginx-1.19.2'
make[1]: Nothing to be done for 'modules'.
make[1]: Leaving directory '/root/nginx-1.19.2'
Is there anything I do wrong here? I really want to try out nchan and want to try to build everything from source to keep up with version changes.
Version 0.97 of nchan does not exist (anymore) at the URL you try to download from.
Sorry, I meant to use v1.2.7, I think in my code it was correct. But just to be sure let me try again within today and report back.
I use Docker to build nchan, this might help you
Dockerfile:
FROM ubuntu:bionic AS builder
ENV NCHAN_VERSION 1.2.2
ENV NGINX_VERSION 1.18.0
RUN apt-get update && apt-get install -qq -y gnupg1 ca-certificates \
&& apt-key adv --keyserver keyserver.ubuntu.com --recv-keys ABF5BD827BD9BF62 \
&& echo "deb https://nginx.org/packages/ubuntu/ bionic nginx" >> /etc/apt/sources.list.d/nginx.list \
&& echo "deb-src https://nginx.org/packages/ubuntu/ bionic nginx" >> /etc/apt/sources.list.d/nginx.list \
&& apt-get update \
&& apt-get install -qq -y wget build-essential libpcre3 libpcre3-dev libssl-dev zlibc zlib1g zlib1g-dev nginx
# Download sources
RUN wget "http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz" -O nginx.tar.gz && \
wget "https://github.com/slact/nchan/archive/v${NCHAN_VERSION}.tar.gz" -O nchan.tar.gz
# Reuse same cli arguments as the nginx binary used to build
RUN CONFARGS=$(nginx -V 2>&1 | sed -n -e 's/^.*arguments: //p') && \
mkdir /usr/src1 && \
tar -zxC /usr/src1 -f nginx.tar.gz && \
tar -xzvf "nchan.tar.gz" && \
NCHAN_DIR="$(pwd)/nchan-${NCHAN_VERSION}" && \
cd /usr/src1/nginx-$NGINX_VERSION && \
./configure --with-compat "$CONFARGS" --add-dynamic-module=$NCHAN_DIR && \
make modules && \
mv ./objs/*.so /
release.sh
#!/bin/bash
set -e
mkdir -p tmp/
docker build -f Dockerfile -t nchan_module:releaser .
DOCKER_UUID=$(cat /dev/urandom | LC_ALL=C tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
docker run -ti --name nchan_module_${DOCKER_UUID} nchan_module:releaser /bin/true
docker cp nchan_module_${DOCKER_UUID}:/ngx_nchan_module.so tmp/
docker rm nchan_module_${DOCKER_UUID}
DOCKER_UUID generation line
DOCKER_UUID=$(cat /dev/urandom | LC_ALL=C tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
might not work on Ubuntu (works for me on macOS), but I've copied it from the internets, so if you google it, you will find a proper variant for Debian/Ubuntu
HTH