Linux环境离线安装Nginx

一、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]# cat >/usr/lib/systemd/system/nginx.service << \EOF
[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
EOF

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://serverip
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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值