- 下载源码包、解压并进入:
# 下载; wget http://nginx.org/download/nginx-1.18.0.tar.gz # 解压; tar -zxvf nginx-1.18.0.tar.gz # 进入; cd nginx-1.18.0/ apt install -y pcre* apt install -y zlib*
- 配置并检测依赖:
./configure --prefix=/home/mu/nginx --user=mu --group=mu --with-http_ssl_module --with-threads --with-http_realip_module --with-http_stub_status_module
编译参数可参考 Building nginx from Sources
- 编译安装:
make && make install
安装时可能出现如下错误:
错误一:
./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.
解决方式:
CentOS
sudo yum install zlib-devel
Ubuntu/Debian
apt-get install zlib1g-dev
apt-get install libpcre3 libpcre3-dev
错误二:
./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.
解决方式:
sudo apt-get install openssl libssl-dev
启动:
cd /home/mu/nginx/sbin/
./nginx
安装后的其他配置参考: