NGINX 的安装 与 启动

本文详细记录了在Linux服务器上从零开始安装Nginx的过程,包括解决安装过程中遇到的常见错误,如C编译器未找到、HTTP重写模块需要PCRE库及HTTP gzip模块需要zlib库等问题的解决方案。同时,提供了启动Nginx的方法及如何处理80端口被占用的情况。

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

注意: 没有图文说明,是我自己一步一步安装的过程中记录一下的,顺便也把步骤记录下来了。

我是新装 Linux 服务器,所以安装过程中出现的错误也是第一遇到,希望对你们有所帮助。

也是方便自己以后再次安装 nignx的时候也可以看我博客了。2019-01-07

-------------------------------------------------------------安装 nginx-------------------------------------------------------------
进入 /usr/local/src 目录
# cd /usr/local/src
下载 nginx 安装包
# wget http://nginx.org/download/nginx-1.14.2.tar.gz
进行解压
# tar zxvf nginx-1.14.2.tar.gz 
安装到指定目录
# ./configure --prefix=/usr/local/nginx

安装过程中如果出现这个错误
./configure: error: C compiler cc is not found
解决方案如下
yum -y install gcc gcc-c++ autoconf automake make
如果出现这个错误 
./configure: error: the HTTP rewrite module requires the PCRE library
...
statically from the source with nginx by using --with-pcre=<path> option.
解决方案 nginx 依赖于 pcre 所以我们要安装 pcre
# yum install pcre
# yum install pcre-devel
如果安装过程中出现 
./configure: error: the HTTP gzip module requires the zlib library.
...
statically from the source with nginx by using --with-zlib=<path> option.
解决方案如下
yum install -y zlib-devel

成功提示信息如下
Configuration summary
+ using system PCRE library
...
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"

接下来我们就进行编译
make && make install

到了这里我们的nginx 也就安装成功了

-------------------------------------------------------------启动 nginx-------------------------------------------------------------
我们进入nginx目录下
# cd /usr/local/nginx
看到 四个目录
--conf 配置文件
--html 网页文件
--logs 日志文件
--sbin 进程文件

那么我们启动就得找 进程文件 这样就启动了
# ./sbin/nginx 
但是注意 nginx 默认端口 是80,以下信息则是80端口被占用
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
方案一:我们可以更改默认端口
# cd /conf
# vi nginx.conf
将80 更改成你想设置的端口号就行了
server {
listen 80;
下面的省略...

方案二:关闭80端口
查看所有端口
# netstat -antp
关闭80端口 对应的PID 如:17789
# kill -9 17789

重新启动就可以了。

好了,就分享这么多,完成了简单的安装和启动,那么接下来的学习就靠我们自己了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值