nginx手动安装-Centos7

本文详细介绍了在CentOS7系统上手动安装Nginx web服务器的步骤,包括安装依赖pcre、zlib,解决编译错误,配置启动Nginx,开放80端口以及查看Nginx状态的相关命令。此外,还提供了Nginx常用管理命令,如启动、停止、重启和查看版本等。
摘要由CSDN通过智能技术生成


在这里插入图片描述

安装命令一览

# 安装相关组件依赖
yum -y install gcc-c++ zlib zlib-devel

# 解压pcre
cd /usr/local/src/
tar -zxvf pcre-8.37.tar.gz
cd pcre-8.37/
# 编译安装pcre
./configure
make && make install
# 查询pcre版本,验证是否安装成功
pcre-config --version

cd ../
tar -zxvf nginx-1.12.2.tar.gz
cd nginx-1.12.2
./configure 
make && make install

# 启动nginx
/usr/local/nginx/sbin/nginx
# 或者
cd /usr/local/nginx/sbin/
./nginx

#放开80端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
systemctl restart firewalld.service
firewall-cmd --reload

# 查看nginx相关线程是否启动
netstat -nltp|grep nginx

1. 安装pcre依赖

将下载到本地的pcre压缩包通过ssh工具,上传至linux服务器中;
在这里插入图片描述

[root@localhost ~]# cd /usr/src/
[root@localhost src]# ls
apache-tomcat-7.0.70.tar.gz  kernels              pcre-8.37.tar.gz
debug                        nginx-1.12.2.tar.gz
[root@localhost src]# tar -zxvf pcre-8.37.tar.gz 
[root@localhost src]# cd pcre-8.37
[root@localhost pcre-8.37]# ./configure 

报错如下:

在这里插入图片描述
原因:没有安装gcc
安装gcc:

[root@localhost pcre-8.37]# yum install gcc

报错如下:

在这里插入图片描述
原因:缺少c++环境依赖
安装c++:

[root@localhost pcre-8.37]# yum install -y gcc-c++

再次运行./configure

[root@localhost pcre-8.37]# ./configure 
#编译安装
[root@localhost pcre-8.37]# make && make install

安装成功页面如下:
在这里插入图片描述
验证pcre是否安装成功:

[root@localhost pcre-8.37]# pcre-config --version
8.37
[root@localhost pcre-8.37]# 

2. 安装Nginx

在官网下载nginx安装包,然后通过ssh上传至服务器的/opt/nginx目录下。

[root@localhost src]# tar -zxvf nginx-1.12.2.tar.gz
[root@localhost src]# cd nginx-1.12.2
[root@localhost nginx-1.12.2]# ./configure 

报错如下:
在这里插入图片描述
原因:缺少zlib的依赖
安装zlib(两个都要装):

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

再次执行:

[root@localhost nginx-1.12.2]# ./configure 
#编译安装
[root@localhost nginx-1.12.2]# make && make install

安装成功页面如下:
在这里插入图片描述

3. 启动nginx

在这里插入图片描述
原因:找不到pcre库,这个库在 /usr/local/lib 目录,执行如下命令:

[root@localhost sbin]# export LD_LIBRARY_PATH=/usr/local/lib/

然后再次启动nginx:
在这里插入图片描述
nginx默认端口是80,需要linux开启80端口才行:

[root@localhost sbin]# vi /etc/sysconfig/iptables
[root@localhost sbin]# /etc/init.d/iptables restart

在这里插入图片描述

在这里插入图片描述

登录验证:
在这里插入图片描述

4、nginx相关命令

nginx命令的操作,需要在/usr/local/nginx/sbin/下进行:

[root@localhost sbin]# cd /usr/local/nginx/sbin/
#1.查看版本
[root@localhost sbin]# ./nginx -v
nginx version: nginx/1.12.2

#2.停止
[root@localhost sbin]# ./nginx -s stop

#3.启动
[root@localhost sbin]# ./nginx

#4.重新加载nginx(更新配置后使用)
[root@localhost sbin]# ./nginx -s reload

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值