由于服务器位于内网环境且无法访问互联网,需要离线安装nginx
,ubuntu18.04
离线安装软件也并不复杂,只是需要较大的耐心去搜集所需的包,不过大家不用担心,我已经为大家准备好了。
一.离线安装GCC
GCC是后续安装的基础,笔者也是在这里花费了大量的时间的,如果你的服务器上已经安装了gcc
相关的包,可以跳过此步了。
1. 准备安装包
下载地址1:链接:百度网盘 请输入提取码
提取码:irit
下载地址2:https://download.csdn.net/download/alfiy/82898527
存放位置:/usr/local/gcc-packages
2. 安装GCC
将安装包解压后,进入解压目录,使用命令
sudo dpkg -i *.deb
就能完成gcc 的离线安装
了.
二. 离线安装nginx
1. 准备离线包
下载地址1:链接:https://pan.baidu.com/s/1J_0xiI78eMDSnj1hs_nSDQ
提取码:ya41
下载地址2: https://download.csdn.net/download/alfiy/82899070
存放位置:/usr/local
2. 安装nginx的依赖包
2.1 安装PCRE
PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库。nginx的http模块使用pcre来解析正则表达式,是nginx必需的依赖。
解压进入PCRE目录
-
cd /usr/local
-
tar -xvf pcre-8.38.tar
-
cd pcre-8.38
-
./configure
-
sudo make
-
sudo make install
2.2 安装zlib
nginx使用zlib对http包的内容进行gzip。
-
cd /usr/local
-
tar -xvf zlib-1.2.11.tar
-
cd zlib-1.2.11.tar
-
./configure
-
sudo make
-
sudo make install
2.3 解压opessl
OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用,OpenSSL包无需安装,只要解压即可。
-
cd /usr/local
-
tar -xvf openssl-1.0.2n.tar.gz
3.安装nginx主程序
3.1 解压nginx主程序包
-
cd /usr/local
-
tar -xvf nginx-1.20.2.tar.gz
3.2 配置nginx的安装设置
-
./configure
-
--sbin-path=/usr/local/nginx/nginx # 配置bin文件的安装位置,不建议修改
-
--conf-path=/usr/local/nginx/nginx.conf # 配置nginx.conf文件的安装位置,不建议修改
-
--pid-path=/usr/local/nginx/nginx.pid # 配置nginx.pid文件的安装位置,不建议修改
-
--with-http_ssl_module
-
--with-pcre=/usr/local/pcre-8.38 # 第三方依赖库prec的安装位置,根据实际情况修改
-
--with-zlib=/usr/local/zlib-1.2.11 # 第三方依赖库zlib的安装位置,根据实际情况修改
-
--with-openssl=/usr/local/openssl-1.0.2n # 第三方依赖库zlib的安装位置,根据实际情况修改
在执行该命令时,取消掉上面命令中的换行与注释。我的安装包都在/usr/local/下,如果你指定了其它安装目录,需要做相应的修改。但是,建议按以上路径进行安装。
或者直接./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-openssl=/opt/openssl-1.0.2p 默认安装到 /usr/local/nginx
3.3 编译安装nginx
-
sudo make
-
sudo make install
4.验证与应用
4.1 配置nginx.conf
-
cd /usr/local/nginx
-
sudo vim ./nginx.conf
4.2 启动nginx
-
cd /usr/local/nginx
-
sudo ./nginx -c ./nginx.conf
4.3 重新加载nginx配置
-
cd /usr/local/nginx
-
sudo ./nginx -s reload
4.4 停止nginx
-
cd /usr/local/nginx
-
sudo ./nginx -s stop
三. Nginx常用操作
-
cd /usr/local/nginx/sbin/
-
./nginx 启动
-
./nginx -s stop 停止
-
./nginx -s quit 安全退出
-
./nginx -s reload 重新加载配置文件 如果我们修改了配置文件,就需要重新加载。
-
ps aux|grep nginx 查看nginx进程