Building NGINX - linux-on-ibm-z/docs GitHub Wiki

Building NGINX

Below versions of NGINX are available in respective distributions at the time of creation of these build instructions:

  • RHEL (8.4, 8.6, 8.7) has 1.14.1
  • RHEL (9.0, 9.1) has 1.20.1
  • Ubuntu 18.04 has 1.14.0
  • Ubuntu (20.04, 22.04) has 1.18.0
  • Ubuntu 22.10 has 1.22.0
  • SLES 12 SP5 has 1.14.2
  • SLES 15 SP3 has 1.19.8
  • SLES 15 SP4 has 1.21.5

The instructions provided below specify the steps to build NGINX version 1.24.0 on Linux on IBM Z for following distributions:

  • RHEL (7.8, 7.9)
  • SLES (12 SP5, 15 SP3, 15 SP4)
  • Ubuntu (18.04, 22.10)

Note:

  • For Ubuntu (20.04, 22.04), Please Refer to this link to install NGINX Stable version from repository.
  • For Rhel (8.x, 9.x), Please Refer to this link to install NGINX Stable version from repository.

General Notes:

  • When following the steps below please use a standard permission user unless otherwise specified.
  • A directory /<source_root>/ will be referred to in these instructions, this is a temporary writable directory anywhere you'd like to place it.

Step 1 : Build and Install NGINX

1.1) Build using script

If you want to build nginx using manual steps, go to STEP 1.2.

Use the following commands to build nginx using the build script. Please make sure you have wget installed.

wget -q https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/NGINX/1.24.0/build_nginx.sh

# Build nginx
bash build_nginx.sh  

If the build completes successfully, go to STEP 2. In case of error, check logs for more details or go to STEP 1.2 to follow manual build steps.

1.2) Install dependencies

export SOURCE_ROOT=/<source_root>/
  • RHEL (7.8, 7.9)

    sudo yum install -y pcre-devel wget tar xz gcc make zlib-devel diffutils
    
  • SLES (12 SP5, 15 SP3, 15 SP4)

    sudo zypper install -y pcre-devel wget tar xz gcc make zlib-devel diffutils gzip 
    
  • Ubuntu (18.04, 22.10)

    sudo apt-get update
    sudo apt-get install -y wget tar gcc make libpcre3-dev openssl libssl-dev zlib1g zlib1g-dev
    

1.3) Download and unpack the NGINX 1.24.0 source package

cd $SOURCE_ROOT
wget http://nginx.org/download/nginx-1.24.0.tar.gz
tar xvf nginx-1.24.0.tar.gz
cd nginx-1.24.0

1.4) Build and Install NGINX

./configure
make
sudo make install
  • Add binary to /usr/sbin
sudo cp /usr/local/nginx/sbin/nginx /usr/sbin/

Note: NGINX will be installed in /usr/local/nginx/sbin/; depending upon user preferences and conventions, it may be necessary to either update PATH or create links to the executable files.

Step 2: Verification(Optional)

Simple Proxy Test

2.1) Prepare a test webpage index.html to serve in /tmp/ folder.

For example, this simple HTML document provides a bare minimum of text:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html>
    <head>
     <title>Test HTML File</title>
     <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    </head>
    <body>
     <p>This is a very simple HTML file.</p>
    </body>
    </html>

2.2) Create a file nginx.conf with following contents in /tmp/ folder.

This is a simple test of NGINX's proxy functionality, with NGINX serving as a proxy between an HTTP user and the webpage:

    worker_processes     3;
    error_log            logs/error.log;
    pid                  logs/nginx.pid;
    worker_rlimit_nofile 8192;

    events
    {
    worker_connections  2048;
    }

    http
    {
    index index.html index.htm index.php;

    default_type application/octet-stream;
    log_format   main '$remote_addr - $remote_user [$time_local]  $status '
       '"$request" $body_bytes_sent "$http_referer" '
       '"$http_user_agent" "$http_x_forwarded_for"';
    access_log   logs/access.log  main;
    sendfile     on;
    tcp_nopush   on;
    server_names_hash_bucket_size 128;

    server
    {
     listen 8080;
     root /tmp;
     location /
     {
     }
    }
    server {
     location / {
     proxy_pass http://localhost:8080/;
     }
    }
    }

This assumes that the webpage from step 1 is stored in /tmp/index.html. If this is not the case, modify the definitions for root and index accordingly.

Create a user and group named as nobody if not present.

2.3) Run NGINX with the provided configuration.

nginx -c /tmp/nginx.conf

Note that this will normally need to be done as root, or NGINX will not have authority to access one or more ports, such as 80 and 8080.

Navigate a web browser to the address of the server running NGINX. The browser should display the webpage specified in index.html.

References:

⚠️ **GitHub.com Fallback** ⚠️