nginx编译和升级

这里记录 nginx 的模块编译和升级操作.

装好依赖 后开始编译

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 准备目录
mkdir nginx ; cd nginx

# 下载tengine https://tengine.taobao.org/download_cn.html
curl https://tengine.taobao.org/download/tengine-3.0.0.tar.gz -o 
tengine-3.0.0.tar.gz
tar xf tengine-3.0.0.tar.gz

# 下载,解压 https://nginx.org/en/download.html
curl http://nginx.org/download/nginx-1.24.0.tar.gz -o nginx-1.24.0.tar.gz
tar -xf nginx-1.24.0.tar.gz
cd nginx-1.24.0

# 监控信息 --with-http_stub_status_module 
# ssl证书 --with-http_ssl_module
# tcp代理和tcp代理证书 --with-stream --with-stream_ssl_module
# tcp代理的时候,把客户端ip传到PROXY协议的header头部 --with-stream_realip_module和--with-http_realip_module建议开启,虽然我一直用header传输
# 启用http2  --with-http_v2_module
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_ssl_module --with-stream --with-stream_ssl_module --with-stream_realip_module --with-http_v2_module --with-http_stub_status_module
make && make install

# 软连接
ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/nginx

# 验证
nginx -t
# 启动
nginx
# 报错 [emerg] getpwnam("nginx") failed
useradd -s /bin/false nginx

GitHub - chobits/ngx_http_proxy_connect_module: A forward proxy module for CONNECT request handling 作用是支持 connection 请求, 也就是正向代理

1
2
3
4
5
6
# clone到解压后的nginx目录
git clone https://github.com/chobits/ngx_http_proxy_connect_module.git
patch -p1 < ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_102101.patch

# 加入编译module
--add-module=ngx_http_proxy_connect_module
1
2
# 加入tengine的内存调试模块
./configure ... --add-module=/root/nginx/tengine-3.0.0/modules/ngx_debug_pool
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# 下载,解压
curl http://nginx.org/download/nginx-1.24.0.tar.gz -o ~/nginx-1.24.0.tar.gz
tar xf ~/nginx-1.24.0.tar.gz

# nginx -V查看现有配置,然后到新版本nginx目录下执行同样配置
./configure 编译参数(configure-arguments)

# 编译  
make
# 备份一下
cp /usr/local/nginx/sbin/nginx nginx.bak
# 停老版本nginx  
nginx -s stop
# 替换文件  
cp objs/nginx /usr/local/nginx/sbin/nginx  
# 测试是否正常  
nginx -t  
# 启动新版本nginx  
nginx