Ubuntu18.04安装NGINX

由于服务器位于内网环境且无法访问互联网,需要离线安装nginxubuntu18.04离线安装软件也并不复杂,只是需要较大的耐心去搜集所需的包,不过大家不用担心,我已经为大家准备好了。

一.离线安装GCC

GCC是后续安装的基础,笔者也是在这里花费了大量的时间的,如果你的服务器上已经安装了gcc

相关的包,可以跳过此步了。

1. 准备安装包

下载地址1:链接:百度网盘 请输入提取码 
                    提取码:irit

下载地址2https://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目录

 
  1. cd /usr/local

  2. tar -xvf pcre-8.38.tar

  3. cd pcre-8.38

  4. ./configure

  5. sudo make

  6. sudo make install

2.2 安装zlib

nginx使用zlib对http包的内容进行gzip。

 
  1. cd /usr/local

  2. tar -xvf zlib-1.2.11.tar

  3. cd zlib-1.2.11.tar

  4. ./configure

  5. sudo make

  6. sudo make install

 2.3 解压opessl

OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用,OpenSSL包无需安装,只要解压即可。

 
  1. cd /usr/local

  2. tar -xvf openssl-1.0.2n.tar.gz

3.安装nginx主程序

3.1 解压nginx主程序包
 
  1. cd /usr/local

  2. tar -xvf nginx-1.20.2.tar.gz

3.2 配置nginx的安装设置
 
  1. ./configure

  2. --sbin-path=/usr/local/nginx/nginx # 配置bin文件的安装位置,不建议修改

  3. --conf-path=/usr/local/nginx/nginx.conf # 配置nginx.conf文件的安装位置,不建议修改

  4. --pid-path=/usr/local/nginx/nginx.pid # 配置nginx.pid文件的安装位置,不建议修改

  5. --with-http_ssl_module

  6. --with-pcre=/usr/local/pcre-8.38 # 第三方依赖库prec的安装位置,根据实际情况修改

  7. --with-zlib=/usr/local/zlib-1.2.11 # 第三方依赖库zlib的安装位置,根据实际情况修改

  8. --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
 
  1. sudo make

  2. sudo make install

4.验证与应用

4.1 配置nginx.conf
 
  1. cd /usr/local/nginx

  2. sudo vim ./nginx.conf

4.2 启动nginx
 
  1. cd /usr/local/nginx

  2. sudo ./nginx -c ./nginx.conf

4.3 重新加载nginx配置
 
  1. cd /usr/local/nginx

  2. sudo ./nginx -s reload

4.4 停止nginx
 
  1. cd /usr/local/nginx

  2. sudo ./nginx -s stop

三. Nginx常用操作

 
  1. cd /usr/local/nginx/sbin/

  2. ./nginx 启动

  3. ./nginx -s stop 停止

  4. ./nginx -s quit 安全退出

  5. ./nginx -s reload 重新加载配置文件 如果我们修改了配置文件,就需要重新加载。

  6. ps aux|grep nginx 查看nginx进程

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值