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 
相关推荐
DuelCode42 分钟前
Windows VMWare Centos Docker部署Springboot 应用实现文件上传返回文件http链接
java·spring boot·mysql·nginx·docker·centos·mybatis
snoopyfly~3 小时前
Ubuntu 24.04 LTS 服务器配置:安装 JDK、Nginx、Redis。
java·服务器·ubuntu
BD_Marathon3 小时前
Ubuntu下Tomcat的配置
linux·ubuntu·tomcat
BD_Marathon4 小时前
Ubuntu:Tomcat里面的catalina.sh
linux·ubuntu·tomcat
BD_Marathon4 小时前
设置LInux环境变量的方法和区别_Ubuntu/Centos
linux·ubuntu·centos
zhaowangji4 小时前
ubuntu 20.04 安装中文输入法 (sougou pin yin)
linux·ubuntu
dyj0959 小时前
【Rancher Server + Kubernets】- Nginx-ingress日志持久化至宿主机
运维·nginx·rancher
PanZonghui10 小时前
Centos项目部署之Nginx部署项目
linux·nginx
Hellc00711 小时前
Nginx 高级 CC 与 DDoS 防御策略指南
运维·nginx·ddos
Maki Winster12 小时前
Peek-Ubuntu上Gif录制工具-24.04LTS可装
linux·ubuntu·peek