Debain 编译 Nginx

442次阅读
没有评论

配置

安装依赖

apt install build-essential zlib1g-dev libpcre3-dev libssl-dev

创建第三方模块存放目录

mkdir nginx_modules

下载源代码文件

wget https://nginx.org/download/nginx-1.26.2.tar.gz && tar -zxvf nginx-1.26.2.tar.gz && cd nginx-1.26.2

添加自带模块

http_v2_module 模块

./configure --prefix=/usr/local/nginx  --with-http_v2_module

http_ssl_module 模块

./configure --prefix=/usr/local/nginx --with-http_ssl_module

添加第三方模块

ngx_http_proxy_connect_module 模块

cd ../nginx_modules && wget https://github.com/chobits/ngx_http_proxy_connect_module/archive/refs/tags/v0.0.7.zip && unzip v0.0.7.zip && cd ../nginx-1.26.2
patch -p1 < ../nginx_modules/ngx_http_proxy_connect_module-0.0.7/patch/proxy_connect_rewrite_102101.patch
./configure --prefix=/usr/local/nginx  --add-module=../nginx_modules/ngx_http_proxy_connect_module-0.0.7 

ngx_cache_purge 模块

cd ../nginx_modules && wget https://github.com/FRiCKLE/ngx_cache_purge/archive/refs/tags/2.3.zip && unzip 2.3.zip && cd ../nginx-1.26.2
./configure --prefix=/usr/local/nginx --add-module=../nginx_modules/ngx_cache_purge-2.3

stream 模块

./configure --prefix=/usr/local/nginx --with-stream

stream_ssl_module 模块

./configure --prefix=/usr/local/nginx --with-stream_ssl_module 

编译和安装

maek && make install

创建服务

 vim /usr/lib/systemd/system/nginx.service 
[Unit]
Description=nginx
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target
chmod +x /usr/lib/systemd/system/nginx.service && systemctl enable nginx &&  systemctl start nginx 

个人操作

./configure --prefix=/usr/local/nginx  --add-module=../nginx_modules/ngx_http_proxy_connect_module-0.0.7 --add-module=../nginx_modules/ngx_cache_purge-2.3 --with-http_ssl_module --with-stream --with-stream_ssl_module --with-http_v2_module
cd /usr/local/nginx && mkdir ssl && mkdir conf.d
ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
正文完
 0
评论(没有评论)