nginx安装(linux版)

本文档详述了在Linux系统中安装Nginx的过程,包括从官网下载最新版本的Nginx,使用yum安装依赖库PCRE和zlib,解决配置时遇到的问题,最后进行编译安装并启动Nginx服务。通过这一系列步骤,读者可以学习到如何在Linux环境中成功部署Nginx服务器。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

nginx安装(linux版)

一、进入官网http://nginx.org/en/download.html,找到最新linux版本,右键复制链接http://nginx.org/download/nginx-1.21.6.tar.gz
在这里插入图片描述
二、下载到/usr/local/src

[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# wget http://nginx.org/download/nginx-1.21.6.tar.gz

在这里插入图片描述
三、解压安装包

[root@localhost src]# ls
nginx-1.21.6.tar.gz
[root@localhost src]# tar -zxvf nginx-1.21.6.tar.gz

四、进入nginx解压目录进行配置

[root@localhost src]# cd ./nginx-1.21.6
[root@localhost nginx-1.21.6]# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  man  README  src
[root@localhost nginx-1.21.6]# ./configure --prefix=/usr/local/nginx

配置时报错,原因是缺少PCRE库

./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.

解决方案:yum安装pcre-devel

[root@localhost nginx-1.21.6]# yum install pcre-devel

输入y进行确认
在这里插入图片描述
重新进行配置

[root@localhost nginx-1.21.6]# ./configure --prefix=/usr/local/nginx --with-pcre

发现还是报错,缺少zlib库

./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@localhost nginx-1.21.6]# 
Socket error Event: 32 Error: 10053.
Connection closing...Socket close.

Connection closed by foreign host.

Disconnected from remote host(远程虚拟机) at 20:27:09.

Type `help' to learn how to use Xshell prompt.
[D:\~]$ 

解决方案:yum安装zlib-devel

[root@localhost nginx-1.21.6]# yum install zlib-devel

输入y进行确认
在这里插入图片描述
进入src目录下载zlib源码包并解压出来

[root@localhost nginx-1.21.6]# cd ..
[root@localhost src]# wget http://www.zlib.net/zlib-1.2.12.tar.gz
[root@localhost src]# tar -zxvf zlib-1.2.12.tar.gz

重新进行配置

[root@localhost nginx-1.21.6]#  ./configure --prefix=/usr/local/nginx

在这里插入图片描述

五、编译安装

[root@localhost nginx-1.21.6]# make
[root@localhost nginx-1.21.6]# make install

查看有没有这个nginx目录

[root@localhost nginx-1.21.6]# ls /usr/local/nginx/
conf  html  logs  sbin
[root@localhost nginx-1.21.6]# 

六、启动

[root@localhost nginx-1.21.6]#  /usr/local/nginx/sbin/nginx
[root@localhost init.d]# netstat -anput | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      21864/nginx: master 

关闭防火墙,在浏览器上输入ip进行验证

[root@localhost ~]# systemctl stop firewalld

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值