Skip to content

Building NGINX

linuxonz edited this page Sep 12, 2024 · 45 revisions

Building NGINX

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

  • RHEL (8.8, 8.10) have 1.14.1
  • RHEL (9.2, 9.4) have 1.20.1
  • SLES (15 SP5, 15 SP6) have 1.21.5
  • Ubuntu (20.04, 22.04) have 1.18.0
  • Ubuntu (24.04) has 1.24.0

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

  • RHEL (8.8, 8.10, 9.2, 9.4)
  • SLES (12 SP5, 15 SP5, 15 SP6)
  • Ubuntu (20.04, 22.04, 24.04)

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.26.2/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 (8.8, 8.10, 9.2, 9.4)

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

    sudo zypper install -y pcre-devel curl wget tar xz gcc make zlib-devel diffutils gzip 
    
  • Ubuntu (20.04, 22.04, 24.04)

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

1.3) Download and unpack the NGINX 1.26.2 source package

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

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:

Clone this wiki locally