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 
相关推荐
缘友一世17 小时前
GLM5.3 CyberSec w4A16本地部署[6]:加载链路与磁盘规划
ubuntu·vllm·glm5.3 cybersec
张张123y19 小时前
2026 Agent 框架怎么选?拆 3 层底层逻辑(运行循环 / 记忆 / 工具协议)+ 一张决策表
linux·ubuntu·microsoft·langgraph·mcp·crewai·agent 框架
longerxin20201 天前
Ubuntu 22.04 ARM64 云镜像开启 root 密钥登录(保留 ubuntu 密钥登录,禁止密码登录)
数据库·ubuntu·postgresql
skywalk81631 天前
FreeBSD仿真环境里的Ubuntu linux系统,安装软件的时候不支持snap怎么办?
linux·运维·ubuntu·系统·freebsd
Cry丶1 天前
ubuntu安装vsftpd
服务器·网络·ubuntu
程序员-King.1 天前
【ROS1】Noetic 开发工作流程与常用命令
c++·ubuntu·ros
时间售卖铺2 天前
Nginx 反向代理
运维·nginx·云原生
life码农2 天前
Nginx location 优先级详解:匹配规则、修饰符与完整代码示例
运维·nginx
承渊政道2 天前
Linux网络学习【传输层协议UDP】
linux·网络·网络协议·学习·ubuntu·udp
爬也要爬着前进2 天前
Prometheus通过Nginx-vts-exporter模块监控nginx服务
运维·nginx·prometheus