手把手带你学习Linux——NGINX

本文介绍了常见的web服务器,重点讲解Nginx的发展及简介。详细阐述了在CentOS上通过yum和源码两种方式安装Nginx的步骤,包括配置官方yum源、下载解压源码包、编译安装等,还介绍了Nginx源码包内各目录及安装脚本的参数含义。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、常见的web服务器

httpd、IIS:政府类网站、银行类网站较多(httpd:中国人民政府网;IIS:招商银行、兴业银行、建设银行等)

Nginx、Tomcat、tengine:社区及电商平台使用较多(Nginx:京东商城、新浪、it猿网等;tengine:简书、淘宝、优快云等)

二、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并提高其性能)

            [root@JSH-01 ~]# yum install -y yum-utils

      2.2 配置Nginx官方yum源

3、查看yum源安装的版本

四、源码安装Nginx

1、下载Nginx 1.18.0源码包并上传时/usr/local/src/目录下(可以通过wget命令直接下载到指定目录)

[root@JSH-01 ~]# cd /usr/local/src/
[root@JSH-01 src]# wget http://nginx.org/download/nginx-1.18.0.tar.gz

2、解压缩

[root@JSH-01 src]# tar zxvf nginx-1.18.0.tar.gz

3、编译(编译过程实质是将各种程序语言转换为系统可以识别的二进制信息)

[root@JSH-01 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)
[root@JSH-01 nginx-1.18.0]# yum install -y gcc  (解决方法1)

[root@JSH-01 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)

[root@JSH-01 nginx-1.18.0]# yum install -y pcre-devel                                       (解决方法2)

[root@JSH-01 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)
[root@JSH-01 nginx-1.18.0]# yum install -y zlib*                                               (解决方法3)

[root@JSH-01 nginx-1.18.0]# ./configure --prefix=/usr/local/nginx/         再次执行后编译完成,如下图所示,同时生成Makefile文件和objs目录

4、编译安装 make && make install

(未完待续)

五、Nginx源码包内各目录介绍

1、Nginx源码包内文件

[root@JSH-01 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 - ****  禁用相关模块

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值