现在位置: 首页 > 博客文章 > 电脑相关 > IT开发 > 服务器 > Nginx > 正文
CentOS 通过源码编译形式安装 Nginx
2021年01月14日 23:45:19 Nginx ⁄ 共 1675字 暂无评论 ⁄ 被围观 2,438次

本篇简单说说在如何在 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 已安装成功。如果打不开上面页面,可能是机器的防火墙没关,先关闭防火墙再进行验证。

使用命令:service iptables stop 或者 systemctl stop firewalld

原文链接:https://blog.csdn.net/tzhuwb/article/details/112644593

给我留言

留言无头像?