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 
相关推荐
一叶龙洲2 小时前
解决Vmware Ubuntu共享文件夹有时无法识别
ubuntu
XRJ040618xrj2 小时前
Nginx下构建PC站点
服务器·前端·nginx
会飞的土拨鼠呀3 小时前
Ubuntu系统缺少 iptables 工具
linux·运维·ubuntu
Fᴏʀ ʏ꯭ᴏ꯭ᴜ꯭.3 小时前
Nginx 平滑升级与回滚超详细指南
运维·nginx
花间相见5 小时前
【AI开发】—— Ubuntu系统使用nvm管理Node.js多版本,版本切换一键搞定(实操完整版)
linux·ubuntu·node.js
.小墨迹5 小时前
apollo中车辆的减速绕行,和加速超车实现
c++·学习·算法·ubuntu·机器学习
小Pawn爷5 小时前
13.virtualbox安装ubuntu
linux·运维·ubuntu
VekiSon5 小时前
Linux内核驱动——Ubuntu 网络启动环境配置与操作
linux·arm开发·嵌入式硬件·ubuntu
YYYing.5 小时前
【Linux/C++进阶篇(二) 】超详解自动化构建 —— 日常开发中的“脚本” :Makefile/CMake
linux·c++·经验分享·ubuntu
Diros1g6 小时前
ubuntu多网卡网络配置
网络·ubuntu·php