专业的编程技术博客社区

网站首页 > 博客文章 正文

nginx源码,nginx基础架构

baijin 2024-12-19 10:11:36 博客文章 7 ℃ 0 评论

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
12

添加www用户

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

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

下载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
12345678910111213141516

安装nginx

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

编译并安装

make && make install1

启动、停止、重启

# 1.启动nginx
shell> nginx
# 可通过ps -ef | grep nginx查看nginx是否已启动成功
# 2.停止nginx
shell> nginx -s stop
# 3. 重新启动
shell> nginx -s reload1234567


nginx默认配置启动成功后,会有两个进程,一个主进程(守护进程),一个工作进程。主进程负责管理工作进程,工作进程负责处理用户的http请求。

配置nginx开机启动

将/usr/bin/nginx命令添加到/etc/rc.d/rc.local文件中,rc.local文件会在系统启动的时候执行。但CentOS7建议将开机启动服务写成服务描述文件添加到系统服务中,所以rc.local默认没有执行权限,需要给它添加执行权限。

shell> vim /etc/rc.d/rc.local
# 添加如下参数
/usr/bin/nginx

shell> chmod +x /etc/rc.d/rc.local12345

或者通过supervisor管理nginx进程,实现开机自动启动,且进程挂掉后自动重启。详情请参考《Supervisor安装与配置(Linux/Unix进程管理工具)》

错误合集

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

1234567

解决办法
安装编译工具

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

12

然后再次编译,可以了,然而又遇到了新问题

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

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

12345678

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

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

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

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


总结:

一起学习的可以后台私信“资料”送学习视频资料包括C/C++,Linux,golang技术,Nginx,ZeroMQ,MySQL,Redis,fastdfs,MongoDB,ZK,流媒体,CDN,P2P,K8S,Docker,TCP/IP,协程,DPDK,ffmpeg等等。。。),免费分享

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表