本文共 3000 字,大约阅读时间需要 10 分钟。
鼠标右击复制链接地址
Mainline version:Mainline 是 Nginx 目前主力在做的版本,可以说是开发版Stable version:最新稳定版,生产环境上建议使用的版本Legacy versions:遗留的老版本的稳定版
# wget http://nginx.org/download/nginx-1.14.0.tar.gz
# tar -zxvf nginx-1.14.0.tar.gz
[root@localhost soft_tar]# lsnginx-1.14.0 nginx-1.14.0.tar.gz[root@localhost soft_tar]# cd nginx-1.14.0[root@localhost nginx-1.14.0]# lsauto 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
错误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=<path> option.
错误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=<path> option.
错误3:需要zlib库,报错信息如上图:
上面这个错误是说需要zlib库 解决办法:[root@localhost ~]# yum install -y zlib-devel
然后回去继续安装配置
[root@localhost nginx-1.14.0]# ./configure
这次没有错误:
[root@localhost nginx-1.14.0]# make[root@localhost nginx-1.14.0]# make install
上面两步没有错误就安装成功了!
web访问Nginx,看到下图就安装成功了。
开始安装完成后,在centos上面测试下是没问题的,web访问也没问题,但是在windows浏览器访问却出错访问不了,后来想想查看下iptables,把iptable关掉再去访问就没有问题。
本机测试:
关闭iptables:
[root@localhost ~]# service iptables stop
以前启动/停止/查看状态某个服务的时候,我们常用的方法是
service [服务名] [动作][root@localhost ~]# service nginx statusnginx: 未被识别的服务[root@localhost ~]#
可是如上,nginx未被识别,下面再解决下这个问题
[root@localhost sbin]# vim nginx
vim编辑(创建)nginx脚本,写入以下内容:
#!/bin/bash## chkconfig: - 85 15# description: Nginx is a World Wide Web server.# processname: nginxnginx=/usr/local/nginx/sbin/nginxconf=/usr/local/nginx/conf/nginx.confcase $1 instart)echo -n "Starting Nginx"$nginx -c $confecho " done";;stop)echo -n "Stopping Nginx"killall -9 nginxecho " done";;#!/bin/bash## chkconfig: - 85 15# description: Nginx is a World Wide Web server.# processname: nginxnginx=/usr/local/nginx/sbin/nginxconf=/usr/local/nginx/conf/nginx.confcase $1 instart)echo -n "Starting Nginx"$nginx -c $confecho " done";;stop)echo -n "Stopping Nginx"killall -9 nginxecho " done";;test)$nginx -t -c $conf;;reload)echo -n "Reloading Nginx"ps auxww | grep nginx | grep master | awk '{print $2}' | xargs kill -HUPecho " done";;restart)$0 stop$0 start;;show)ps -aux|grep nginx;;*)echo -n "Usage: $0 {start|restart|reload|stop|test|show}";;esac
转载地址:http://hapul.baihongyu.com/