Debian编译安装Nginx
手动编译安装Nginx比较复杂,但是平时一般使用最多。原因:
1.便于管理
编译安装的Nginx,其安装地址可控,如果需要卸载,执行反编译即可。
2.模块可控
Nginx有其丰富的模块库,如:ngx-fancyindex。使用Docker或软件包管理器安装的Nginx,模块有时不方便载入。
预先准备环境和用户
bash
## 更新环境和安装依赖
sudo apt-get -y update
sudo apt-get install -y build-essential libpcre3 libpcre3-dev zlib1g-dev openssl libssl-dev
#添加用户和组
groupadd www
useradd -g www www
下载解压编译安装
bash
# 下载
wget https://nginx.org/download/nginx-1.26.3.tar.gz
# 解压Nginx
tar -xf nginx-1.26.3.tar.gz
# 进入解压后出现的目录,已备接下来的编译
cd nginx-1.26.3
# 编译
./configure \
--prefix=/opt/nginx \
--user=www \
--group=www \
--with-file-aio \
--with-threads \
--with-http_addition_module \
--with-http_auth_request_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_mp4_module \
--with-http_random_index_module \
--with-http_realip_module \
--with-http_secure_link_module \
--with-http_slice_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_sub_module \
--with-http_v2_module \
--with-mail \
--with-mail_ssl_module \
--with-stream \
--with-stream_realip_module \
--with-stream_ssl_module \
--with-stream_ssl_preread_module
# 安装
make && make install
启动
bash
# 启动Nginx
/opt/nginx/sbin/nginx