一、常见的web服务器
httpd、IIS:政府类网站、银行类网站较多(httpd:中国人民政府网;IIS:招商银行、兴业银行、建设银行等)
Nginx、Tomcat、tengine:社区及电商平台使用较多(Nginx:京东商城、新浪、it猿网等;tengine:简书、淘宝、CSDN等)
二、Nginx的发展及简介
详见开源版Nginx官网:http://nginx.org/ 目前的稳定版本为1.18.0(一般而言,偶数版本为稳定版本)
三、yum安装Nginx(通过Nginx官方源安装)
1、官方网站说明
http://nginx.org/en/linux_packages.html#RHEL-CentOS
2、根据官网提示,执行以下步骤配置官方yum源
2.1 安装管理repository及扩展包的工具(维护YUM并提高其性能)
[[email protected] ~]# yum install -y yum-utils
2.2 配置Nginx官方yum源
3、查看yum源安装的版本
四、源码安装Nginx
1、下载Nginx 1.18.0源码包并上传时/usr/local/src/目录下(可以通过wget命令直接下载到指定目录)
[[email protected] ~]# cd /usr/local/src/
[root@JSH-01 src]# wget http://nginx.org/download/nginx-1.18.0.tar.gz
2、解压缩
[[email protected] src]# tar zxvf nginx-1.18.0.tar.gz
3、编译(编译过程实质是将各种程序语言转换为系统可以识别的二进制信息)
[r[email protected] nginx-1.18.0]# ./configure --prefix=/usr/local/nginx/
checking for OS
+ Linux 3.10.0-1160.el7.x86_64 x86_64
checking for C compiler ... not found
./configure: error: C compiler cc is not found (错误信息1)
[[email protected] nginx-1.18.0]# yum install -y gcc (解决方法1)
[ro[email protected] nginx-1.18.0]# ./configure --prefix=/usr/local/nginx/
checking for getaddrinfo() ... found
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. (错误信息2)
[[email protected] nginx-1.18.0]# yum install -y pcre-devel (解决方法2)
[r[email protected] nginx-1.18.0]# ./configure --prefix=/usr/local/nginx/
checking for zlib library ... not found
./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)
[[email protected] nginx-1.18.0]# yum install -y zlib* (解决方法3)
[[email protected] nginx-1.18.0]# ./configure --prefix=/usr/local/nginx/ 再次执行后编译完成,如下图所示,同时生成Makefile文件和objs目录
4、编译安装 make && make install
(未完待续)
五、Nginx源码包内各目录介绍
1、Nginx源码包内文件
[[email protected] nginx-1.18.0]# ls
auto CHANGES CHANGES.ru conf configure contrib html LICENSE man README src
2、目录介绍
auto:自动检测目录
CHANGES:版本更新记录
CHANGES.ru:版本更新记录(俄语版)
conf:配置文件
configure:预编译的shell脚本,检测当前系统是否满足安装条件
contrib:存放Nginx特性文件,比如语法高亮
html:发布目录(包含首页文件及错误页面)
LICENSE:许可声明
man:帮助文档存放目录
README:自述文件
src:包含Nginx运行的重要模块(core核心模块文件,event事件模块,http代理模块,mail邮件模块)
六、关于Nginx的安装脚本介绍,通过 ./configure --help 查看
1、--prefix=PATH set installation prefix 定义Nginx的安装目录
2、--user=USER set non-privileged user forworker processes 创建一个虚拟用户,用于管理nginx服务的worker进程
--group=GROUP set non-privileged group forworker processes 创建一个虚拟用户组,用于管理nginx服务的worker进程
3、--with - **** 开启相关模块
4、--without - **** 禁用相关模块