CentOS 软件安装之Nginx源码安装

step1.首先wget下载源码包

鼠标右击复制链接地址

CentOS 软件安装之Nginx源码安装_第1张图片
Mainline version:Mainline 是 Nginx 目前主力在做的版本,可以说是开发版
Stable version:最新稳定版,生产环境上建议使用的版本
Legacy versions:遗留的老版本的稳定版
# wget http://nginx.org/download/nginx-1.14.0.tar.gz
step2.解压nginx-1.14.0.tar.gz包
# tar -zxvf nginx-1.14.0.tar.gz
step3.进入解压的文件夹安装nginx
[root@localhost soft_tar]# ls
nginx-1.14.0  nginx-1.14.0.tar.gz
[root@localhost soft_tar]# cd nginx-1.14.0
[root@localhost nginx-1.14.0]# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  man  README  src
[root@localhost nginx-1.14.0]# ./configure

./configure: error: C compiler cc is not found

CentOS 软件安装之Nginx源码安装_第2张图片

错误1:未找到C编辑器,报错信息如下:
解决办法:

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


然后回去继续安装配置

[root@localhost nginx-1.14.0]# ./configure

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

CentOS 软件安装之Nginx源码安装_第3张图片

错误2:需要pcre模块,报错信息如上图:
解决办法:

[root@localhost ~]# yum -y install pcre-devel


然后回去继续安装配置

[root@localhost nginx-1.14.0]# ./configure

又出现一个错误:

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

CentOS 软件安装之Nginx源码安装_第4张图片

错误3:需要zlib库,报错信息如上图:
上面这个错误是说需要zlib库
解决办法:

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



然后回去继续安装配置

[root@localhost nginx-1.14.0]# ./configure

这次没有错误:

CentOS 软件安装之Nginx源码安装_第5张图片
图片.png
[root@localhost nginx-1.14.0]# make
[root@localhost nginx-1.14.0]# make install

上面两步没有错误就安装成功了!

web访问Nginx,看到下图就安装成功了。

CentOS 软件安装之Nginx源码安装_第6张图片

开始安装完成后,在centos上面测试下是没问题的,web访问也没问题,但是在windows浏览器访问却出错访问不了,后来想想查看下iptables,把iptable关掉再去访问就没有问题。

本机测试:

CentOS 软件安装之Nginx源码安装_第7张图片
图片.png

关闭iptables:

[root@localhost ~]# service iptables stop
step4:把nginx添加到系统服务中,使其可以使用service nginx start/stop/restart等。

以前启动/停止/查看状态某个服务的时候,我们常用的方法是
service [服务名] [动作]

[root@localhost ~]# service nginx status
nginx: 未被识别的服务
[root@localhost ~]#

可是如上,nginx未被识别,下面再解决下这个问题

[root@localhost sbin]# vim nginx

vim编辑(创建)nginx脚本,写入以下内容:

#!/bin/bash
#
# chkconfig: - 85 15
# description: Nginx is a World Wide Web server.
# processname: nginx

nginx=/usr/local/nginx/sbin/nginx
conf=/usr/local/nginx/conf/nginx.conf
case $1 in
start)
echo -n "Starting Nginx"
$nginx -c $conf
echo " done"
;;
stop)
echo -n "Stopping Nginx"
killall -9 nginx
echo " done"
;;
#!/bin/bash
#
# chkconfig: - 85 15
# description: Nginx is a World Wide Web server.
# processname: nginx

nginx=/usr/local/nginx/sbin/nginx
conf=/usr/local/nginx/conf/nginx.conf
case $1 in
start)
echo -n "Starting Nginx"
$nginx -c $conf
echo " done"
;;
stop)
echo -n "Stopping Nginx"
killall -9 nginx
echo " done"
;;
test)
$nginx -t -c $conf
;;
reload)
echo -n "Reloading Nginx"
ps auxww | grep nginx | grep master | awk '{print $2}' | xargs kill -HUP
echo " done"
;;
restart)
$0 stop
$0 start
;;
show)
ps -aux|grep nginx
;;
*)
echo -n "Usage: $0 {start|restart|reload|stop|test|show}"
;;
esac

你可能感兴趣的:(CentOS 软件安装之Nginx源码安装)