准备环境
安装编译器
sudo yum -y install gcc gcc-c++
安装pcre软件包(使nginx支持http rewrite模块)
sudo yum install -y pcre pcre-devel
安装 openssl-devel(使 nginx 支持 ssl)
sudo yum install -y openssl openssl-devel
安装zlib
sudo yum install -y zlib zlib-devel gd gd-devel
创建用户 nginx
这步可做可不做,无关紧要
sudo useradd -s /sbin/nologin nginx
安装编译
下载解压
# 下载
wget https://nginx.org/download/nginx-1.23.3.tar.gz
# 或者
curl -L https://nginx.org/download/nginx-1.23.3.tar.gz -o nginx-1.23.3.tar.gz
# 解压
tar xvfz nginx-1.23.3.tar.gz
配置
# 编译配置项帮助查看,https://nginx.org/en/docs/configure.html
./configure --help
# 如果希望使用Prometheus监控,需要带上stub_status模块
./configure \
--sbin-path=/usr/local/nginx/nginx \
--conf-path=/usr/local/nginx/nginx.conf \
--pid-path=/usr/local/nginx/nginx.pid \
--with-http_ssl_module \
--with-pcre \
--with-threads \
--with-stream \
--with-file-aio \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_stub_status_module
编译
make && make install
启动
./nginx
监控
增加配置
server {
location /nginx_status {
stub_status;
access_log off;
allow 127.0.0.1;
deny all;
}
}
重新加载配置文件
nginx -s reload
测试
curl http://127.0.0.1:80/nginx_status
Active connections: 1
server accepts handled requests
4 4 4
Reading: 0 Writing: 1 Waiting: 0
标签:http,tar,编译,--,devel,nginx,install,安装
From: https://www.cnblogs.com/youxiong/p/17205633.html