Nginx——特性介绍及安装

4 篇文章 0 订阅
1 篇文章 0 订阅

Nginx——特性介绍及安装


Nginx是一款免费、开源、性能强大且非常流行的服务器,主要有三个功能:Web Server , Reverse Proxy Server , IMAP or POP3 Proxy Server 。Nginx是为了解决互联网业内著名的 “C10K” 问题而生,且因其具有丰富的特性、极其强大的性能、配置简单、工作稳定及资源占用低等特点而闻名于世。

Nginx的主要功能有:作为Web服务器可与httpd服务一样提供静态的Web资源,结合FastCGI/uwSGI/SCGI等协议反代动态资源请求,http/https协议的反向代理,imap4/pop3协议的反向代理,tcp/udp协议的请求转发(四层转发)。

Nginx在功能丰富的同时,其配置文件种类非常多。但相对于httpd的配置文件来说,Nginx配置文件逻辑严谨,条理清晰,配置方法相对简单。我们将在下一篇博客中着重详细介绍。

【注】本文全部示例以CentOS7.3作为运行环境。


Nginx特性

Nginx 的Master/Worker 程序架构

  • 一个master进程:

负责加载和分析配置文件、管理worker进程、平滑升级

  • 一个或多个worker进程

处理并响应用户请求

  • 缓存相关的进程:

cache loader:载入缓存对象

cache manager:管理缓存对象

Nginx特性

  • 支持异步读写(AIO)和非阻塞(unblock)
  • 支持事件驱动(Singal Driven)
  • 模块动态装卸载(DSO)

Nginx模块

Nginx是高度模块化,从1.9版本以后支持(部分)模块动态装卸载,模块分为以下几类
- 核心模块 core module
- 标准模块 standart module
1. Http modules :用于提供web服务或web的反向代理服务
http模块分为:

标准模块 Standard HTTP modules

可选模块 Optional HTTP modules
  1. Mail modules :用于提供邮件相关功能
  2. Stream modules :用于提供四层转发功能
    • 第三方模块 3rd Party modele

程序安装 Nginx installation

安装方式

Nginx程序依赖环境:

两个标准包组:
“Development Tools” 和 “Server Platform Development”

依赖程序包:
pcre-devel,openssl-devel,zlib-devel

  • 从EPEL官方yum源或者从Nginx官网获取Nginx程序包,使用yum方法安装【推荐】
  • 从Nginx官网获取源码后编译安装
yum安装

此方法适用于大多数情况,如果有特殊需求可以使用编译安装,可在配置号yum源后安装

编译安装
  • 准备软件环境,安装上述依赖包组和程序包
]# tar -xvf nginx-1.10.2.tar.gz
]# cd ngingx-1.10.2
  • 创建组和用户
]# groupadd -r nginx
]# useradd -r -g nginx nginx
  • 编译安装,此处的配置选项参考EPEL源中yum安装nginx的选项,较为实用
]# ./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-google_perftools_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E'
]# make -j 4 && make install
  • 创建对应目录
]# mkdir -pv /var/lib/nginx/tmp/{client_body,proxy,fastcgi,uwsgi,scgi}
  • 启动服务,Nginx默认监听80端口
]# systemctl start nginx
]# ss -tnl
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值