Linux 安装 nginx 步骤

1.准备工作,安装nginx需要依赖以下三个包,也就是说得先安装这三个。。

  1. SSL功能需要openssl库,下载地址:https://www.openssl.org/source/
  2. gzip模块需要zlib库,下载地址:http://www.zlib.net/
  3. rewrite模块需要pcre库,下载地址:https://ftp.pcre.org/pub/pcre/
  4. Nginx的安装包:下载地址为:http://nginx.org/en/download.html

将以上下载的几个包使用 Xftp 工具上传到 Linux 系统中,一般我们是上传到 /usr/local 此路径下。

[root@centos7u6 ~]# cd /usr/local
[root@centos7u6 local]# ll
total 220244
-rw-r--r--   1 root    root      1064925 Jul 14 16:08 nginx-1.21.1.tar.gz
-rw-r--r--   1 root    root      9823400 Jun 23 15:17 openssl-1.1.1k.tar.gz
-rw-r--r--   1 root    root      2053336 Jul 14 16:33 pcre-8.38.tar.gz
-rw-r--r--   1 root    root       607698 Jun 23 15:21 zlib-1.2.11.tar.gz

注:以上几个版本经过本人亲测是没有问题的,nginx-1.20 之前的版本,官方已经宣布是有漏洞的;pcre-8.00 版本有漏包,可能会导致后续 make 操作无法执行。

2.安装三个依赖包

①首先安装 openssl ,先进入到 /usr/local/ 路径下,再依次执行以下命令:

a.  tar -zxvf  openssl-1.1.1k.tar.gz
b.  cd openssl-1.1.1k
c.  ./config
d.  make
e.  make install

②接下来安装 zlib ,方法同上,先进入到 /usr/local/ 路径下,再依次执行以下命令:

a.  tar -zxvf  zlib-1.2.11.tar.gz
b.  cd zlib-1.2.11
c.  ./configure 
d.  make
e.  make install

③接下来安装 pcre ,方法同上,先进入到 /usr/local/ 路径下,再依次执行以下命令:

a.  tar -zxvf  pcre-8.38.tar.gz
b.  cd pcre-8.38
c.  ./configure 
d.  make
e.  make install

注:在安装 pcre 时,执行 ./configure 可能会出现以下报错:
error: You need a C++ compiler for C++ support
解决方法: 执行 yum install -y gcc gcc-c++ 安装 gcc

3.接下来正式安装NGINX

先进入到 /usr/local/ 路径下,再依次执行以下命令:

a.  tar -zxvf  nginx-1.21.1.tar.gz
b.  cd nginx-1.21.1
c.  ./configure --with-pcre=../pcre-8.38/ --with-zlib=../zlib-1.2.11/ --with-openssl=../openssl-1.1.1k/
d.  make
e.  make install

注:执行 ./configure 可能会出现以下报错:
error: You need a C++ compiler for C++ support
解决方法:同上执行 yum install -y gcc gcc-c++ 安装 gcc

4.检测NGINX是否安装成功

依次执行以下命令:

[root@centos7u6 ~]# cd /usr/local/nginx/sbin
[root@centos7u6 sbin]# ll
total 11620
-rwxr-xr-x 1 root root 7878392 Jul 14 17:25 nginx
-rwxr-xr-x 1 root root 4015408 Jul 14 16:56 nginx.old
[root@centos7u6 sbin]# ./nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

看到 ok 和 successful 我们就知道 nginx 已经安装成功了,接下来执行启动命令 ./nginx 就大功告成了。

[root@centos7u6 sbin]# ./nginx
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值