Linux环境离线安装Nginx

小柒博客 Nginx评论412字数 3327阅读11分5秒阅读模式

一、Nginx简介

Nginx (engine x) 是一个高性能的HTTP和反向代理web服务器,同时也提供了IMAP/POP3/SMTP服务。Nginx是由伊戈尔·赛索耶夫为俄罗斯访问量第二的Rambler.ru站点(俄文:Рамблер)开发的,公开版本1.19.6发布于2020年12月15日。

Nginx是一款轻量级的Web服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,在BSD-like协议下发行。其特点是占有内存少,并发能力强,事实上nginx的并发能力在同类型的网页服务器中表现较好。

二、准备软件包

zlib:https://www.zlib.net/zlib-1.3.1.tar.gz

pcre:https://nchc.dl.sourceforge.net/project/pcre/pcre/8.45/pcre-8.45.tar.gz

nginx:http://nginx.org/download/nginx-1.26.2.tar.gz

openssl:https://openssl.org/source/old/1.1.1/openssl-1.1.1k.tar.gz

软件已打包下载地址:https://mirrors.yangxingzhen.com/package/nginx_pacakge.zip

三、Centos 7.9离线安装Nginx

1、上传软件包

使用ftp工具或者Xftp工具将nginx_pacakge.zip上传至服务器/usr/local文件夹下(放到哪里根据自身要求进行)

2、安装gcc

[root@localhost local]# unzip nginx_pacakge.zip

[root@localhost local]# cd nginx_pacakge/gcc/

[root@localhost gcc]# rpm -ivh *.rpm --nodeps --force

其中--nodeps表示忽略依赖检查,--force表示强制安装。

3、安装g++

[root@localhost gcc]# cd ../g++/

[root@localhost g++]# rpm -ivh *.rpm --nodeps --force

其中--nodeps表示忽略依赖检查,--force表示强制安装。

4、安装pcre

1)解压安装包

[root@localhost g++]# cd ../

[root@localhost nginx_pacakge]# tar xf pcre-8.45.tar.gz

2)预编译

[root@localhost nginx_pacakge]# cd pcre-8.45

[root@localhost pcre-8.45]# ./configure

3)编译及安装

[root@localhost pcre-8.45]# make && make install

5、安装zlib

1)解压安装包

[root@localhost pcre-8.45]# cd ../

[root@localhost nginx_pacakge]# tar xf zlib-1.3.1.tar.gz

2)预编译

[root@localhost nginx_pacakge]# cd zlib-1.3.1

[root@localhost zlib-1.3.1]# ./configure

3)编译和安装

[root@localhost zlib-1.3.1]# make && make install

6、安装openssl

1)解压安装包

[root@localhost zlib-1.3.1]# cd ../

[root@localhost nginx_pacakge]# tar xf openssl-1.1.1k.tar.gz

2)预编译

[root@localhost openssl-1.1.1k]# ./config

3)编译和安装

[root@localhost openssl-1.1.1k]# make && make install

7、安装Nginx

1)解压安装包

[root@localhost openssl-1.1.1k]# cd ..

[root@localhost nginx_pacakge]# tar xf nginx-1.26.2.tar.gz

2)预编译

[root@localhost nginx_pacakge]# cd nginx-1.26.2

[root@localhost nginx-1.26.2]# useradd -s /sbin/nologin nginx

[root@localhost nginx-1.26.2]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-stream --with-pcre=../pcre-8.45 --with-zlib=../zlib-1.3.1 --with-openssl=../openssl-1.1.1k --with-http_gzip_static_module --with-http_realip_module

3)编译及安装

[root@localhost nginx-1.26.2]# make && make install

4)配置系统服务

[root@localhost nginx-1.26.2]# ln -sf /usr/local/nginx/sbin/nginx /usr/sbin/

[root@localhost nginx-1.26.2]# vim /usr/lib/systemd/system/nginx.service

[Unit]
Description=Nginx Server 1.26.2
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID

[Install]
WantedBy=multi-user.target

5)启动Nginx

[root@localhost nginx-1.26.2]# systemctl daemon-reload

[root@localhost nginx-1.26.2]# systemctl enable nginx

[root@localhost nginx-1.26.2]# systemctl start nginx

6)访问Nginx页面

# 浏览器输入http://192.168.74.128,如下图所示

7)常用基本操作

1、启动Nginx

[root@localhost nginx-1.26.2]# systemctl start nginx

2、停止Nginx

[root@localhost nginx-1.26.2]# systemctl stop nginx

3、重载Nginx

[root@localhost nginx-1.26.2]# systemctl reload nginx

4、重启Nginx

[root@localhost nginx-1.26.2]# systemctl restart nginx

5、查询Nginx运行状态

[root@localhost nginx-1.26.2]# systemctl status nginx

6、查询Nginx进程

[root@localhost nginx-1.26.2]# ps -ef |grep nginx

7、查询Nginx监听端口

[root@localhost nginx-1.26.2]# netstat -lntup |grep nginx

若文章图片、下载链接等信息出错,请在评论区留言反馈,博主将第一时间更新!如本文“对您有用”,欢迎随意打赏,谢谢!

继续阅读
Wechat
微信扫一扫,加我!
weinxin
微信公众号
微信扫一扫,关注我!
weinxin
Nginx最后更新:2024-10-17
小柒博客
  • 本文由 小柒博客 发表于 2024年10月16日09:23:44
  • 声明:本站所有文章,如无特殊说明或标注,本站文章均为原创。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。转载请务必保留本文链接:https://www.yangxingzhen.com/10112.html
匿名

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

拖动滑块以完成验证