CentOS 通过源码编译形式安装 Nginx

本篇简单说说在如何在 Linux 系统上通过源码编译的形式安装 Nginx,纯属笔记。

Nginx 下载官网路径:http://nginx.org/en/download.html

部署环境

Linux 版本:centos6.9-x64

Nginx 版本:nginx-1.19.6.tar.gz

关闭 Linux 机器防火墙

第一步,上传安装包

上传 Nginx 安装包 nginx-1.19.6.tar.gz,这里上传到 /root 下。

第二步,解压安装包

对第一步上传的安装包进行解压并进入到解压目录,命令如下。

命令1:tar -zxvf nginx-1.19.6.tar.gz

命令2:cd nginx-1.19.6

第三步,检查安装依赖

这里计划把 Nginx 安装到 /usr/local 下,检查依赖命令如下。

命令:./configure --prefix=/usr/local/nginx

结果信息如下:

checking for OS
 + Linux 2.6.32-696.el6.x86_64 x86_64
checking for C compiler ... not found

./configure: error: C compiler cc is not found

说明缺少 C 编译环境,执行下面命令安装相关环境包。

命令:yum -y install gcc gcc-c++

再次执行检查依赖命令,结果如下:

[root@test242 nginx-1.19.6]# ./configure --prefix=/usr/local/nginx
...

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

[root@test242 nginx-1.19.6]# 

第四步,安装 pcre

命令:yum -y install pcre-devel

再次执行检查依赖命令,结果如下:

[root@test242 nginx-1.19.6]# ./configure --prefix=/usr/local/nginx
...

./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.

[root@test242 nginx-1.19.6]# 

第五步,安装 zlib

命令:yum -y install zlib-devel

再次执行检查依赖命令,可以看到不再缺少依赖。

第六步,编译

命令:make

第七步,安装

命令:make install

第八步,启动

进入 Nginx 的安装目录 /usr/local/nginx,并启动 Nginx 服务。

命令1:cd /usr/local/nginx/

命令2:./sbin/nginx

第九步,测试

通过浏览器访问:http://机器IP:80 测试是否安装成功。

看到上面测试页,说明 Nginx 已安装成功。如果打不开上面页面,可能是机器的防火墙没关,先关闭防火墙再进行验证。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值