How to Compile Nginx With Source Code

How to compile nginx with source code

Download source code

  • Access nginx.org to download latest stable version of nginx.
1
2
wget  https://nginx.org/download/nginx-1.16.0.tar.gz
tar -zxvf nginx-1.16.0.tar.gz

Compile source code

1
2
3
4
5
cd nginx-1.16.0
apt update && apt install -y gcc build-essential
./configure --prefix=/home/echowings/nginx
make
make install

Trouble shooting

  • PCRE missing error.
1
2
3
4
5
6
7
  ./configure: error: the HTTP rewrite module requires the PCRE library.

You can either disable the module by using —without–http_rewrite_module

option, or install the PCRE library into the system, or build the PCRE library

statically from the source with nginx by using —with–pcre=<path> option.

We need to install pcre library to support it.

1
2
3
4
5
# Install pcre for rhel or centos
yum install pcre-devel

# Install pcre for debian or ubuntu
apt install -y libpcre3 libpcre3-dev
  • gzip error.
1
2
3
4
./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.

We need to install gzip library.

1
2
3
4
5
# For rhel or centos
yum install zlib-devel 

# For debian or ubuntu
apt install zlib1g zlib1g-dev

Reference

Licensed under CC BY-NC-SA 4.0
Last updated on Nov 08, 2024 12:49 UTC
Built with Hugo
Theme Stack designed by Jimmy