njs icon indicating copy to clipboard operation
njs copied to clipboard

how can I install njs-cli ?

Open magic-thomas opened this issue 3 years ago • 11 comments

I installed njs with source in Docker.

How can I install njs-cli.

magic-thomas avatar Oct 01 '22 20:10 magic-thomas

Hi @magic-thomas,

The CLI binary is named njs.

Make command to build the CLI is make njs.

xeioex avatar Oct 01 '22 20:10 xeioex

Hi.

I tried with make njs but it get error.

my configure is this in Dockerfile.


RUN apk add --no-cache \
    build-base \
    ca-certificates \
    curl \
    gcc \
    libc-dev \
    libgcc \
    linux-headers \
    make \
    musl-dev \
    openssl \
    openssl-dev \
    pcre \
    pcre-dev \
    pkgconf \
    pkgconfig \
    zlib-dev

;;
;;

RUN \
    ./configure \
    --prefix=/usr/local/nginx \
    --conf-path=/etc/nginx/nginx.conf \
    --with-threads \
    --with-file-aio \
    --with-http_ssl_module \
    --with-debug \
    --with-http_stub_status_module \
    --with-http_ssl_module \
    --with-http_v2_module \
    --with-http_stub_status_module \
    --with-http_realip_module \
    --with-stream \
    --with-http_secure_link_module \
    --with-cc-opt="-O3 -mpopcnt" \
    --add-module=/tmp/nginx-rtmp-module-${NGINX_RTMP_VERSION} \
    --add-module=/tmp/njs-${NGINX_NJS_VERSION}/nginx  && \
    make && \ //-> tried with make njs , but failed. 
    make install

Can you give me some tip?

magic-thomas avatar Oct 01 '22 21:10 magic-thomas

tried with make njs , but failed.

Please, share the configure and compilation logs.

xeioex avatar Oct 01 '22 21:10 xeioex

Dockerfile



ARG NGINX_VERSION=1.22.0
ARG NGINX_RTMP_VERSION=1.2.2
ARG FFMPEG_VERSION=5.1
ARG NGINX_NJS_VERSION=0.7.6

##############################
# Build the NGINX-build image.
FROM alpine:3.16.1 as build-nginx
ARG NGINX_VERSION
ARG NGINX_RTMP_VERSION
ARG MAKEFLAGS="-j4"
ARG NGINX_NJS_VERSION

# Build dependencies.
RUN apk add --no-cache \
    build-base \
    ca-certificates \
    curl \
    gcc \
    libc-dev \
    libgcc \
    linux-headers \
    make \
    musl-dev \
    openssl \
    openssl-dev \
    pcre \
    pcre-dev \
    pkgconf \
    pkgconfig \
    zlib-dev

# apt install git libpcre3-dev libssl-dev zlib1g-dev ffmpeg libxml2-dev -y


WORKDIR /tmp


# Get nginx source.
RUN wget https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz && \
    tar zxf nginx-${NGINX_VERSION}.tar.gz 

# Get nginx-njs module.
RUN wget -O njs-${NGINX_NJS_VERSION}.tar.gz https://github.com/nginx/njs/archive/refs/tags/${NGINX_NJS_VERSION}.tar.gz && \ 
    tar zxf njs-${NGINX_NJS_VERSION}.tar.gz  

# Get nginx-rtmp module.
RUN wget https://github.com/arut/nginx-rtmp-module/archive/v${NGINX_RTMP_VERSION}.tar.gz && \
    tar zxf v${NGINX_RTMP_VERSION}.tar.gz 

# Compile nginx with nginx-rtmp module.
WORKDIR /tmp/nginx-${NGINX_VERSION}

RUN \
    ./configure \
    --prefix=/usr/local/nginx \
    --conf-path=/etc/nginx/nginx.conf \
    --with-threads \
    --with-file-aio \
    --with-http_ssl_module \
    --with-debug \
    --with-http_stub_status_module \
    --with-http_ssl_module \
    --with-http_v2_module \
    --with-http_stub_status_module \
    --with-http_realip_module \
    --with-stream \
    --with-http_secure_link_module \
    --with-cc-opt="-O3 -mpopcnt" \
    --add-module=/tmp/nginx-rtmp-module-${NGINX_RTMP_VERSION} \
    --add-module=/tmp/njs-${NGINX_NJS_VERSION}/nginx  && \
    make hls && \
    make install


##########################
# Build the release image.
FROM alpine:3.16.1
# LABEL MAINTAINER Alfred Gutierrez <[email protected]>

# Set default ports.
ENV HTTP_PORT 80
# ENV HTTPS_PORT 443
ENV RTMP_PORT 1935

RUN apk add --no-cache \
    ca-certificates \
    gettext \
    openssl \
    pcre \
    lame \
    libogg \
    curl \
    libass \
    libvpx \
    libvorbis \
    libwebp \
    libtheora \
    opus \
    rtmpdump \
    x264-dev \
    x265-dev

COPY --from=build-nginx /usr/local/nginx /usr/local/nginx
COPY --from=build-nginx /etc/nginx /etc/nginx

# Add NGINX path, config and static files.
ENV PATH "${PATH}:/usr/local/nginx/sbin"
COPY nginx.conf /etc/nginx/nginx.conf.template
RUN mkdir -p /data/www/livestream && mkdir /www
RUN mkdir -p /data/www/html
RUN mkdir -p /var/log/nginx
COPY static /www/static

EXPOSE 1935
EXPOSE 80
# EXPOSE 443

CMD envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < \
    /etc/nginx/nginx.conf.template > /etc/nginx/nginx.conf && \
    nginx

Error message


make: *** No rule to make target 'hls'.  Stop.
The command '/bin/sh -c ./configure     --prefix=/usr/local/nginx     --conf-path=/etc/nginx/nginx.conf     --with-threads     --with-file-aio     --with-http_ssl_module     --with-debug     --with-http_stub_status_module     --with-http_ssl_module     --with-http_v2_module     --with-http_stub_status_module     --with-http_realip_module     --with-stream     --with-http_secure_link_module     --with-cc-opt="-O3 -mpopcnt"     --add-module=/tmp/nginx-rtmp-module-${NGINX_RTMP_VERSION}     --add-module=/tmp/njs-${NGINX_NJS_VERSION}/nginx  &&     make hls &&     make install' returned a non-zero code: 2

It stops at make hls && \

magic-thomas avatar Oct 01 '22 21:10 magic-thomas

Why make hls? Where did you take the configure and build options for nginx?

xeioex avatar Oct 01 '22 22:10 xeioex

Why make hls? Where did you take the configure and build options for nginx?

Ah. it is mistake..

But I tried just now. with make njs...

It failed too.

make: *** No rule to make target 'njs'.  Stop.

magic-thomas avatar Oct 01 '22 22:10 magic-thomas

njs binary will come, when you build njs modules. I was talking about building standalone njs binary.

xeioex avatar Oct 01 '22 22:10 xeioex

Ok, I see, thanks.

And Can I ask on more thing here.

Dockerfile is same with up file with make only.

And I added this in Dockerfile

COPY njs-examples /etc/nginx/njs-examples

the 'njs-examples' is from https://github.com/nginx/njs-examples.

And nginx.conf is following.


http {
    js_path "/etc/nginx/njs-examples/njs";

    js_import utils.js;
    js_import main from http/hello.js;


    ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; 
    ssl_prefer_server_ciphers on;

    server {
        listen 80;
        listen [::]:80;

        server_name _;
        root /data/www/html/web;

        index index.html index.php;

        location / {
            add_header Cache-Control no-cache;
            add_header Access-Control-Allow-Origin *;
            try_files $uri $uri/ =404;
        }

        location = /version {
            js_content utils.version;
        }

        location /hello {
            js_content main.hello;
        }
    }
}

when I access http://my-ip/version or /hello, the response is downloaded, not shown in web browser.

How can I fix this ?

p.s. I made it simple to glance at.

magic-thomas avatar Oct 01 '22 22:10 magic-thomas

@magic-thomas

Please, do not try to shift the burden of your own work on strangers. Before asking new questions, please, study this document.

xeioex avatar Oct 01 '22 22:10 xeioex

Sorry for my rudeness.

Really thanks for your concerns.

magic-thomas avatar Oct 01 '22 22:10 magic-thomas

@magic-thomas, Alpine Linux provides njs package, so this is all unnecessary, just apk add njs and you’re done (and apk add nginx nginx-mod-http-js if you want nginx as well).

jirutka avatar Oct 02 '22 12:10 jirutka