ubuntu 编译安装nginx及安装nginx_upstream_check_module模块

一、下载安装包

bash 复制代码
# 下载nginx_upstream_check_module模块
wget https://codeload.github.com/yaoweibin/nginx_upstream_check_module/zip/master

# 解压
unzip  master

# 下载nginx 1.21.6
wget https://github.com/nginx/nginx/archive/refs/tags/release-1.21.6.tar.gz 

# 解压
tar xf release-1.21.6.tar.gz  

二、安装依赖包

bash 复制代码
apt-get update
apt-get install gcc libpcre3 libpcre3-dev zlib1g zlib1g-dev openssl libssl-dev  libtool build-essential -y 
sudo apt-get install libxslt-dev libgd-dev libgeoip-dev -y 

三、编译安装

bash 复制代码
# 移动到安装包目录下
cd /opt/nginx-release-1.21.6/

# 自定义要安装的插件和module
./auto/configure --prefix=/usr/local/nginx --add-module=/opt/nginx_upstream_check_module-master/  --with-cc-opt='-g -O2 -fdebug-prefix-map=/build/nginx-lUTckl/nginx-1.18.0=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fPIC' --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-compat --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --with-http_addition_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_xslt_module=dynamic --with-stream=dynamic --with-stream_ssl_module --with-mail=dynamic --with-mail_ssl_module

# 开始编译
make

# 安装
make install

# 将编译后的nginx 拷贝到
cp /usr/local/nginx/sbin/nginx /usr/sbin/.

四、配置systemd守护

bash 复制代码
# 创建nginx守护进程文件
vim /usr/lib/systemd/system/nginx.service

# 文件内容如下
[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop

[Install]
WantedBy=multi-user.target
bash 复制代码
# 启动nginx服务
systemctl  start nginx.service

# 查看nginx状态
systemctl  status  nginx.service

# 设置nginx开机自启
systemctl  enable  nginx.service

# 停止nginx服务
systemctl  stop  nginx.service

脚本解释:

Unit: 服务的启动顺序和依赖关系

Description:对该服务的描述;

After:在b.target服务组启动后,再启动本服务;

Service:服务具体执行的方式

ExecStart,ExecStop,ExecReload等:启动命令组,分别是服务启动时,停止时,重启时,启动前,启动后,停止后执行的命令;

Type:服务启动类型。默认simple表示ExecStart为主进程,notify类似于simple,启动结束后会发出通知信号。另外还有forking,oneshot,dbus,idle等类型;

Install: 把服务放在哪个服务组

WantedBy:服务所在的服务组。

五、检查安装结果

bash 复制代码
# 查看nginx版本
nginx -v

# 查看nginx安装的模块
nginx -V

# 查看nginx端口
netstat  -nltp 
相关推荐
梦在深巷、4 小时前
nginx配置之负载均衡
运维·nginx·负载均衡
iRayCheung4 小时前
Kind方式部署k8s单节点集群并创建nginx服务对外访问
nginx·kubernetes·kind
xiaobin889994 小时前
【2025最新版】VMware虚拟机下载安装教程 保姆级图文详解(附安装包+常用镜像Linux,win11,ubuntu,centos)
linux·其他·ubuntu·centos
ALex_zry5 小时前
Ubuntu 20.04 C++开发环境搭建指南(2025版)
linux·c++·ubuntu
Eric.Lee202119 小时前
Ubuntu shell指定conda的python环境启动脚本
python·ubuntu·conda·shell
影龙帝皖21 小时前
Linux服务之lvs+keepalived nginx+keepalived负载均衡实例解析
linux·nginx·lvs
dubochao_xinxi1 天前
✅ TensorRT Python 安装精简流程(适用于 Ubuntu 20.04+)
开发语言·python·ubuntu
yangshuo12811 天前
风车OVF镜像:解放AI开发限制的Ubuntu精简系统
linux·人工智能·ubuntu
flypig哗啦啦1 天前
ubuntu服务器版启动卡在start job is running for wait for...to be Configured
linux·运维·ubuntu
子非衣1 天前
Ubuntu系统挂载磁盘并配置开机自动挂载
linux·运维·ubuntu