Nginx之解压编译安装

Nginx的安装方法有两种,一种是rpm安装 方式,另一种是解压安装的方式,第一种方法比较的简单,第二种相对折腾一点,我在第二种安装方式中,编译Nginx出错./configure: error: C compiler cc is not found,
同时还有,checking for PCRE library … not found,还有导致的原因是没有编译工具

安装前准备

对于nginx编译安装需要先安装编译 的工具,然后再安装nginx依赖

yum -y install gcc gcc-c++ autoconf automake make      
yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel

   
   
  • 1
  • 2

添加www用户

添加www用户,如果没有可能会报错nginx: [emerg] getpwnam(“www”) failed

#添加www 用户
groupadd -f www
useradd -g www www

   
   
  • 1
  • 2
  • 3

下载nginx

#管网镜像
http://nginx.org/download/

#获取nginx,官方地址
wget http://nginx.org/download/nginx-1.10.1.tar.gz

#1.6.2 这个老版本,不支持 --with-stream 模块,1.9.0后,才支持的,建议大家使用的时候注意
#wget http://nginx.org/download/nginx-1.6.2.tar.gz

#这个是我自己七牛的服务器
wget http://yellowcong.qiniudn.com/nginx-1.10.1.tar.gz
#nginx 2019/4/2 新得版本
wget http://nginx.org/download/nginx-1.15.9.tar.gz

#解压 /usr/local/nginx 目录
tar -zxvf nginx-1.10.1.tar.gz

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

安装nginx

第一步是配置,第二步是编译安装

配置nginx

#进入到nginx-1.10.1 ,并配置nginx
cd nginx-1.10.1 

#配置nginx
#–prefix 指定安装的目录
#/usr/local/nginx 是安装目录,不能和自己下载的文件目录重了
#./configure --prefix=/usr/local/nginx

#带ssl stub_status模块 添加strem模块 –with-stream,这样就能传输tcp协议了
#http_stub_status_module 状态监控
#http_ssl_module 配置https
#stream 配置tcp得转发
#http_gzip_static_module 压缩
#http_sub_module 替换请求
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-stream

#带用户得方式
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-stream --with-http_gzip_static_module --with-http_sub_module

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

到nginx的目录下,然后配置nginx
这里写图片描述

看到了结果,就差不多 代表成功了

这里写图片描述

编译安装

只要出现上面的,差不多就是完事了,可以编译了,如果还是有错误,可以使用yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel命令,安装所有依赖

#编译安装
make && make install

 
 
  • 1
  • 2

这里写图片描述

安装成功

安装成功后,会在./configure --prefix=/usr/local/nginx,指定的目录/usr/local/nginx创建4个 文件夹。具体功能下面有介绍。


#启动 nginx服务
/usr/local/nginx/sbin/nginx
#停止服务
/usr/local/nginx/sbin/nginx -s stop

#重启服务
/usr/local/nginx/sbin/nginx -s reload

#查看启动情况
ps -ef|grep nginx

#查看是否启动成功
curl 192.168.100.10

#查看端口情况
netstat -ano|grep 80

#查看nginx版本
./sbin/nginx -V

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

查看nginx的版本
在这里插入图片描述
nginx正常运行
这里写图片描述

网页访问正常
这里写图片描述

查看端口情况
这里写图片描述

配置nginx

Nginx之虚拟主机-yellowcong

目录结构

目录作用
conf用于存储nginx配置文件
html用于存放静态网页
logs存放日志
sbin用于存放 nginx这种工具

这里写图片描述

错误合集

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

错误消息

[root@1088d470c710 nginx-1.10.1]# ./configure
checking for OS
 + Linux 3.10.0-514.26.2.el7.x86_64 x86_64
checking for C compiler ... not found

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

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

解决办法
安装编译工具

[root@1088d470c710 nginx-1.10.1]# yum -y install gcc gcc-c++ autoconf automake make                                                              
  • 1
  • 2

然后再次编译,可以了,然而又遇到了新问题
这里写图片描述

2、checking for PCRE library … not found

pcre没有发现的问题,需要安装pcre ,他作用是让ngnix支持rewrite功能

checking for PCRE library ... not found
checking for PCRE library in /usr/local/ ... not found
checking for PCRE library in /usr/include/pcre/ ... not found
checking for PCRE library in /usr/pkg/ ... not found
checking for PCRE library in /opt/local/ ... not found

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

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
3、安装pcre

我打算安装的,结果发现这鸡毛已经安装过了,然后我需要在./configure的时候指定目录./configure --with-pcre=./auto/lib/pcre

[root@1088d470c710 nginx-1.10.1]# yum install pcre
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Package pcre-8.32-15.el7_2.1.x86_64 already installed and latest version
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

简单说一下centos如何查找文件

#查找文件,需要获取pcre的安装位置
find -name pcre

 
 
  • 1
  • 2

4、安装zlib

还缺少zlib library信息,感觉编译nginx是一个错误,直接使用rpm安装包多爽,安装zlib吧,别说别的了

 yum -y install make zlib zlib-devel gcc-c++ libtool

 
 
  • 1

错误信息

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

 
 
  • 1
  • 2
  • 3
  • 4

这里写图片描述

5、cp: “conf/koi-win” 与"/usr/local/nginx/nginx-1.6.2/conf/koi-win" 为同一文件

文件为同一个文件的问题

cp: "conf/koi-win" 与"/usr/local/nginx/nginx-1.6.2/conf/koi-win" 为同一文件
make[1]: *** [install] 错误 1
make[1]: 离开目录“/usr/local/nginx/nginx-1.6.2”
make: *** [install] 错误 2
  • 1
  • 2
  • 3
  • 4
  • 5

这里写图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值