Linux下安装及运行nginx

本文详细介绍了如何在Linux系统中安装Nginx,包括下载、配置过程,以及可能遇到的PCRE、gcc/g++和zlib库缺失问题的解决方法。重点讲解了如何安装和配置PCRE库、gcc/g++编译器和zlib库,确保Nginx正常运行。

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

安装nginx

下载地址: https://nginx.org/en/download.html
在这里插入图片描述
这里选择nginx稳定linux版

把文件上传至linux系统中,不会上传的朋友,可以参考这篇文章 https://blog.csdn.net/weixin_45433031/article/details/120497126

解压文件:

tar -zxvf nginx-1.22.0

在这里插入图片描述
依次执行下面代码进行配置:

./configure
make
make install

配置成功后输入下方命令检测

whereis nginx

若出现目录,则安装成功。

安装nginx过程中可能会出现的bug以及解决办法:

缺少PCRE库

如果没有安装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.

安装PCRE库

我们可以去下载一下PCRE库,下载地址:https://sourceforge.net/projects/pcre/
在这里插入图片描述
找到最新版的tar.gz文件下载就可以了

下载后上传至linux系统中,使用下面命令解压

tar -zxvf pcre-8.45.tar.gz

解压后给予pcre-8.45目录读写权限

chmod -R 777 pcre-8.45

给予权限后进入pcre-8.45目录运行

./configure

若报错

error: Invalid C++ compiler or C++ compiler flags

说明没有安装c++编译器,首先分别查看一下gcc 和g++ 是否安装

gcc --version
g++ --version

安装gcc和g++

安装gcc

sudo apt install gcc

安装g++

sudo apt install g++

gcc和g++安装好之后回到pcre-8.45目录再次执行

./configure

成功后依次执行

make

make install

pcre库到这就算安装成功了,现在回到nginx目录下执行

./configure

缺少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.

安装zlib库

安装zlib库,下载地址:http://www.zlib.net/fossils/
我安装的是最新版2022年的,在最下面
在这里插入图片描述
解压安装步骤:

进入zlib根目录后
./configure
make
make install

运行nginx

使用下方命令找到nginx安装路径

whereis nginx

查看nginx目录 -> config目录下的nginx.conf 查看端口号
在这里插入图片描述
默认配置下都是80

返回nginx根目录
进入sbin目录,里面只有一个可执行文件nginx,运行

./nginx

运行后,输入ifconfig查看服务器ip

然后在本机网址上搜索IP+端口号就可以进入nginx页面了
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值