Loading

nginx编译安装-CentOS_x86

环境信息

操作系统: CentOS Linux 7 (Core)
架构:x86
nginx版本:1.25.5

编译

安装依赖包

yum install gcc gcc-c++ make unzip pcre pcre-devel zlib zlib-devel libxml2 libxml2-devel  readline readline-devel ncurses ncurses-devel perl-devel perl-ExtUtils-Embed openssl-devel -y

下载nginx源码包

wget http://nginx.org/download/nginx-1.25.5.tar.gz
tar xvf nginx-1.25.5.tar.gz
cd nginx-1.25.5

编译

./configure \
  --sbin-path=/usr/local/nginx/sbin/ \
  --conf-path=/usr/local/nginx/nginx.conf \
  --pid-path=/usr/local/nginx/nginx.pid \
  --with-http_ssl_module \
  --with-file-aio \
  --with-threads \
  --with-http_v2_module \
  --with-http_ssl_module \
  --with-http_gzip_static_module \
  --with-http_gunzip_module \
  --with-http_sub_module \
  --with-http_auth_request_module \
  --with-http_stub_status_module \
  --with-mail_ssl_module \
  --with-mail \
  --with-stream \
  --with-stream_ssl_module \
  --with-stream_realip_module \
  --with-stream_ssl_preread_module \
  --with-pcre 
make
make install

编译完成查看版本

$ /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.25.5
built by gcc 7.3.0 (GCC)
built with OpenSSL 1.1.1f  31 Mar 2020
TLS SNI support enabled
configure arguments: --sbin-path=/usr/local/nginx/sbin/ --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module --with-file-aio --with-threads --with-http_v2_module --with-http_ssl_module --with-http_gzip_static_module --with-http_gunzip_module --with-http_sub_module --with-http_auth_request_module --with-http_stub_status_module --with-mail_ssl_module --with-mail --with-stream --with-stream_ssl_module --with-stream_realip_module --with-stream_ssl_preread_module --with-pcre

安装部署

创建系统服务,为了方便管理 NGINX 服务,可以创建一个 systemd 服务文件。

创建 systemd 服务文件,创建一个名为 nginx.service 的文件:

sudo vi /etc/systemd/system/nginx.service
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PIDFile=/usr/local/nginx/nginx.pid
PrivateTmp=true

[Install]
WantedBy=multi-user.target

启动并启用 NGINX 服务

sudo systemctl daemon-reload
sudo systemctl start nginx
sudo systemctl enable nginx

通过以下命令检查 NGINX 服务状态:

systemctl status nginx
posted @ 2024-09-04 18:54  亚里士多智  阅读(12)  评论(0编辑  收藏  举报