Git Product home page Git Product logo

nginx-binaries's Introduction

nginx and njs standalone binaries

Binaries Workflow

This project provides standalone nginx and njs (NGINX JavaScript) binaries for any Linux system [1] (x86_64, aarch64, ppc64le), macOS (x86_64), and Windows (x86_64). It also provides a JS library for downloading these binaries (for use in integration tests).

You can also download the binaries manually from https://jirutka.github.io/nginx-binaries/ or binaries branch (see Files Repository). They are built automatically and periodically using GitHub Actions (see config).

JS Library

JS Workflow npm Version Dependency Count

Installation

# using npm:
npm install --save-dev nginx-binaries
# or using yarn:
yarn add --dev nginx-binaries

Usage Example

import { NginxBinary, NjsBinary } from 'nginx-binaries'

await NginxBinary.versions({ version: '^1.21.5' })
// => ['1.21.5', '1.21.6', '1.22.0']

await NginxBinary.download({ version: '1.22.x' })
// => '[...]/node_modules/.cache/nginx-binaries/nginx-1.22.0-x86_64-linux'

await NjsBinary.versions({ version: '^0.7.0' })
// => ['0.7.1', '0.7.2', '0.7.3', '0.7.4']

await NjsBinary.download({ version: '^0.7.0', variant: 'debug' }, '.tmp/njs')
// => '.tmp/njs'

API

NginxBinary / NjsBinary

cacheDir (string)

Path to the cache directory where the repository index and binaries are stored.

Defaults to .cache/nginx-binaries/ relative to the nearest writable node_modules (nearest to process.cwd()) or nginx-binaries/ in the system-preferred temp directory.

cacheMaxAge (number)

Maximum age in minutes for the cached repository index in cacheDir to be considered fresh. If the cached index is stale, the Downloader tries to refresh it before reading.

Defaults to 480 (8 hours).

repoUrl (string)

URL of the repository with binaries.

Caution: After changing repoUrl, you should delete old index.json in cacheDir or disable index cache by setting cacheMaxAge to 0.

Defaults to 'https://jirutka.github.io/nginx-binaries'.

timeout (number)

Fetch response timeout in milliseconds.

Defaults to 10000 (10 seconds).

download (query: Query, destFilePath?: string) ⇒ Promise<string>

Downloads a binary specified by query and stores it in the cacheDir or in destFilePath, if provided. Returns path to the file.

If the file already exists and the checksums match, it just returns its path.

If multiple versions satisfies the version range, the one with highest version number is selected.

search (query: Query) ⇒ Promise<IndexEntry[]>

Returns metadata of available binaries that match the query.

variants (query?: Query) ⇒ Promise<string[]>

Returns all the available variants matching the query.

versions (query?: Query) ⇒ Promise<string[]>

Returns all the available versions matching the query.

Query

version (?string)

Specify required version as exact version number or a SemVer version range.

Example: '1.8.0', '1.8.x', '^1.8.0'

variant (?string)

Specify build variant of the binary (e.g. debug). Defaults to an empty string, i.e. the default variant.

os (?string)

Specify target OS. Defaults to the host OS.

arch (?string)

Specify target CPU architecture. Defaults to the host architecture.

IndexEntry

name (string)

Name of the program: 'nginx' or 'njs'.

version (string)

Version of the program.

variant (string)

The build variant of the binary (e.g. debug). An empty string indicates the default variant.

os (string)

OS platform for which this binary was built: 'darwin' (macOS), 'linux' (Linux), or 'win32' (Windows).

arch (string)

CPU architecture for which this binary was built: 'armv7', 'aarch64', 'ppc64le', or 'x86_64'.

filename (string)

Full name of the binary file.

date (string)

Date and time (ISO-8601) at which the binary was built.

size (number)

Size of the binary file in bytes.

checksum (string)

Checksum of the binary file in format <algorithm>:<hash>.

Example: 'sha1:7336b675b26bd67fdda3db18c66fa7f64691e280'

bundledLibs (Object.<string, string>)

A record of all libraries (or modules) statically linked into the binary and the version number.

Example:
{
  'openssl': '1.1.1i-r0',
  'echo-nginx-module': '0.62',
}

Logging

  1. If anylogger is available and initialized (any adapter has been registered), then:

    • all log messages will go through anylogger logger nginx-binaries.

  2. If debug is available, then:

    • debug messages will be logged via debug logger nginx-binaries, others (error, warn, info) via console.

  3. otherwise:

    • error, warn, and info messages will be logged via console, debug messages will be discarded.

If none of these options is suitable, you can provide your own logger using setLogger(object):

import { setLogger } from 'nginx-binaries'

setLogger({
  warn: console.warn,
  error: console.error,
  // undefined logging functions will be replaced with no-op
})

Files Repository

The built binaries are stored in binaries branch of this git repository which is published on https://jirutka.github.io/nginx-binaries/.

The repository contains the following types of files:

  • index.{csv,json,html} — Repository index in CSV, JSON and HTML formats.

  • <name>-<version>[-<variant>]-<arch>-<os>[.exe] — Program binary for particular architecture and OS.

  • <name>-<version>[-<variant>]-<arch>-<os>[.exe].sha1 — SHA-1 checksum of the binary file.

  • <name>-<version>[-<variant>]-<arch>-<os>[.exe].sources — List of all source tarballs and system-provided static libraries from which the binary was built.

See IndexEntry for description of <name>, <version> etc. Suffix .exe is used for Windows binaries only.

Binaries

Program Version Range(s) Variant(s) OS Architecture(s)

nginx

1.18.x (EOL)
1.19.x (EOL) [2]
1.20.x (EOL)
1.21.x (EOL)
1.22.x (old stable)
1.23.x (EOL)
1.24.x (stable)
1.25.x (mainline)

default

Linux

x86_64
aarch64
ppc64le
armv7 [3]

macOS

x86_64

Windows

x86_64 (x64)

njs

0.x.x [4]

default
debug

Linux

x86_64
aarch64
ppc64le
armv7 [3]

macOS

x86_64

nginx

Linux binary is statically linked with musl libc, jansson, openssl (3.x), pcre and zlib from Alpine Linux 3.18. It’s compiled with debug mode, threads and aio.

macOS binary is statically linked with jansson, openssl@3, pcre and zlib from Homebrew. It’s compiled with debug mode, threads and aio.

Windows binary is statically linked with latest openssl 3.1.x, pcre 8.x and zlib 1.2.x built from sources. It’s compiled with debug mode and patches from nginx-build-msys2 made by @myfreeer.

Included Modules

Built-In Modules:

Extra Modules: [5]

Since nginx 1.22.0, the stable and mainline versions of nginx include the latest version of njs available at the time of building. The old stable versions of nginx include the latest minor (i.e. x.Y.z) version of njs released prior to the release of a new stable nginx (and the latest patch version available at the time of building). That is, it’s the same as in NGINX’s own packages.

3rd Party Modules:

nginx binaries include the latest version of the third-party modules available at the time of building.

njs

Linux binary is statically linked with musl libc, libedit, openssl (3.x), ncurses, pcre and zlib from Alpine Linux 3.18.

macOS binary is statically linked with libedit, [email protected], ncurses, pcre and zlib from Homebrew.


1. nginx binaries are built as standalone static executables, so they works on every Linux system regardless of used libc.
2. The first available nginx version in branch 1.19.x is 1.19.5.
3. As of January 2023, binaries for armv7 are no longer built — gcc runs out of memory when building njs using the QEMU emulator. If you want support for armv7, let me know in issues.
4. The first available njs version is 0.5.0.
5. Modules that are provided by NGINX but released separately.
6. njs is not supported on Windows, see nginx/njs#320

nginx-binaries's People

Contributors

dependabot[bot] avatar ivanitskiy avatar jirutka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

nginx-binaries's Issues

Issue trying to load njs

I have a sample config:

load_module modules/ngx_http_js_module.so;

worker_processes 1;


events {
    worker_connections 1024;
}

http {
    js_import hello.js;
    limit_req_zone $binary_remote_addr zone=one:10m rate=10r/s;
    server {
        listen ${PORT};

        location / {
            proxy_pass http://localhost:4000;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            limit_req zone=one;
        }

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

but when I try to run it I get the error:

ERR 2023/10/12 11:00:53 [emerg] 7#7: dlopen() "/home/vcap/modules/ngx_http_js_module.so" failed (Dynamic loading not supported) in /home/vcap/app/sample_ngx.conf:1

Where Do I configure the ngx_http_js_module.so? from the njs cli?

Adding lua module

Is there a way to include the Lua module in this package? I'm using it with njs and lua development. It is great so far with njs, but we really want to test our lua scripts.

Any hint?

nginx 1.25 should contain njs 0.8.0

./node_modules/.cache/nginx-binaries/nginx-1.25.1-x86_64-linux -V
nginx version: nginx/1.25.1
built with OpenSSL 3.1.1 30 May 2023
TLS SNI support enabled
configure arguments: --prefix=. --sbin-path=nginx --conf-path=nginx.conf --pid-path=nginx.pid --lock-path=nginx.lock --error-log-path=stderr --http-log-path=access.log --http-client-body-temp-path=client_body_temp --http-proxy-temp-path=proxy_temp --user=nobody --group=nogroup --with-cc=cc --with-cc-opt='-Os -fomit-frame-pointer -pipe' --with-ld-opt='-static -Wl,--as-needed -Wl,-Map,linker.map' --with-debug --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_auth_request_module --with-http_secure_link_module --without-http_ssi_module --without-http_mirror_module --without-http_geo_module --without-http_split_clients_module --without-http_fastcgi_module --without-http_uwsgi_module --without-http_scgi_module --without-http_grpc_module --without-http_memcached_module --with-file-aio --with-threads --add-module=njs-0.7.12/nginx --add-module=nginx-auth-jwt-0.2.1 --add-module=nginx-keyval-0.1.0 --add-module=ngx_devel_kit-0.3.2 --add-module=echo-nginx-module-0.63 --add-module=headers-more-nginx-module-0.34 --add-module=set-misc-nginx-module-0.33

--add-module=njs-0.7.12/nginx

This should be 0.8.0.

I'm using https://github.com/jirutka/njs-typescript-starter, it already has testing set up using this repo. I was debugging for 2hours why its not working, turns out I had to polyfill Array.from. as nginx-binaries still using njs 0.7.12.

Using the nginx-1.24.0-x86_64-linux version does not work with SSL on Fedora 37

Trying out njs-typescript-starter on Fedora 37; running npm test failed to start the nginx server (1.24.0) with the error

nginx-testing: Starting nginx 1.24.0 on port(s): 35289

  1) /hello?name=njs

  0 passing (418ms)
  1 failing

  1) /hello?name=njs:
     RequestError: socket hang up
      at ClientRequest.<anonymous> (node_modules/got/dist/source/core/index.js:970:111)
      at Object.onceWrapper (node:events:628:26)
      at ClientRequest.emit (node:events:525:35)
      at ClientRequest.origin.emit (node_modules/@szmarczak/http-timer/dist/source/index.js:43:20)
      at TLSSocket.socketOnEnd (node:_http_client:505:9)
      at TLSSocket.emit (node:events:525:35)
      at endReadableNT (node:internal/streams/readable:1358:12)
      at connResetException (node:internal/errors:704:14)
      at TLSSocket.socketOnEnd (node:_http_client:505:23)
      at TLSSocket.emit (node:events:525:35)
      at endReadableNT (node:internal/streams/readable:1358:12)
      at processTicksAndRejections (node:internal/process/task_queues:83:21)

Digging in to the reason, I found that SSL seemed to be causing the issue. By turning off the SSL options, the tests completed successfully.

Executing npm start-nginx:

⏚ [: … njs-typescript-starter] master(+67/-17)* ± npm run start-nginx

> [email protected] start-nginx
> start-nginx --version 1.24.x --port 8090 --watch dist/ integration-tests/nginx.conf

nginx-testing: Starting nginx 1.24.0 on port(s): 8090
2023/09/28 15:21:14 [alert] 144253#144253: OPENSSL_init_ssl() failed (SSL: error:030000A9:digital envelope routines::unknown option:name=rh-allow-sha1-signatures, value=yes error:0700006D:configuration file routines::module initialization error:module=alg_section, value=evp_properties retcode=-1      )
2023/09/28 15:21:14 [warn] 144253#144253: the "ssl" directive is deprecated, use the "listen ... ssl" directive instead in /home/phantomjinx/programming/js/njs-typescript-starter/integration-tests/.nginx.conf~:11

So, trying to understand why SSL maybe the issue, I noticed the same error when running the downloaded nginx binary from .cache/nginx-binaries:

./nginx-1.24.0-x86_64-linux 
2023/09/28 15:05:17 [alert] 141506#141506: OPENSSL_init_ssl() failed (SSL: error:030000A9:digital envelope routines::unknown option:name=rh-allow-sha1-signatures, value=yes error:0700006D:configuration file routines::module initialization error:module=alg_section, value=evp_properties retcode=-1      )

It would seem that the rh-allow-sha1-signatures is a RHEL config option for SSL and not recognised in Fedora (just an educated guess). So maybe the linux nginx binary is not so compatible with Fedora?

This was corroborated by installing a fedora version of nginx with the njs-module. Neither this 3rd party version from getpagespeed or the fedora nginx rpm from their official repo produce this error.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.