nginx编译安装

准备环境

安装编译器

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 
posted @   有熊  阅读(37)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示