Nginx介绍

作者: xhz的个人小屋 | 来源:发表于2018-05-26 17:40 被阅读0次

1.Nginx最大的特点

1,静态小文件(1M),支持高并发,同时占用资源少。
2,占用资源少
3,配置简单,轻量。
4,功能丰富。
5,使用epoll模型,使得nginx可以高并发。(对比apache select的模型)。

2.Nginx所具备的其他www服务特性如下

1,支持基于名字,端口,IP的多虚拟主机配置
2,支持rewrite模块,支持URI重写以及正则表达式匹配
3,支持基于客户端IP地址和HTTP基本认证的访问控制
4,支持http响应速率限制
5,支持同一IP地址的并发连接或请求限制。

3.Ngnix服务常用环境:

A.www web服务,邮件服务,邮件代理服务
B.负载均衡(反向代理proxy)
C.web cache(缓存),类似产品有squid

4. Ngnix的应用场合:

1,提供静态服务(图片,视频,html,js,css,flv,jpg,gif)和lightted很像,几万并发。
2,提供动态服务,nginx+fastcgi的方式运行php,jsp,并发量为500-1500。Apache+php,lighttpd+fcgi php。
3,反向代理,负载均衡,日PV2000W以下,并发1万以下,都可以用Nginx做反向代理。类似产品有Haproxy,F5,A10。
4,缓存服务,类似于SQUID,VARNISH。

5.主要应用场景:

1,web服务器(首选)
静态文件,ngnix(首选)
动态文件,配合fastcgi支持php
2,反向代理(负载均衡),1000-2000W PV,并发6000
3,缓存(使用不是很多)

6.Nginx支持虚拟主机:

一个server标签就是一个虚拟主机。
1,基于域名的虚拟主机,通过域名来区分虚拟主机(常用:外部网站)
2,基于端口的虚拟主机,通过端口来区分虚拟主机(常用:公司的内部网站,网站的后台)
3,基于IP地址的虚拟主机,不支持ifconfig配置。

7.Nginx编译安装:

1,安装pcre Perl兼容正则表达式。

yum install pcre pcre-devel -y

2,ssl module支持加密,需要openssl Library

yum install openssl-devel openssl -y

3,编译安装nginx

./configure \
--prefix=/usr/local/nginx-1.6.3 \
--with-http_ssl_module \
--with-http_stub_status_module \
--user=nginx \
--group=nginx

useradd -s /sbin/nologin -M nginx
make && make install

4,重启之前检测配置文件:

sbin/nginx –t

5,Nginx的虚拟主机的别名设置:
server_name www.xxx.com xxx.com;
别名的一个作用:为每个nginx机器上配置不同的别名,再在本地机器hosts上配置之后单独测试机器可用性

7. Nginx简化配置:

# vim conf/nginx.conf

worker_processes auto;
events {
 worker_connections 1024;
}
http {
 include mime.types;
 default_type application/octet-stream;
 sendfile on;
 keepalive_timeout 65;
 #nginx vhosts config
 include extra/www.conf;
 include extra/bbs.conf;
 include extra/blog.conf;
}
# vim conf/extra/www.conf
server {
 listen 80;
 server_name www.xxx.com xxx.com;
 location / {
 root html/www;
 index index.html index.htm;
 }
 error_page 500 502 503 504 /50x.html;
 location = /50x.html {
 root html;
 }
}

Nginx状态信息:
访问自身状态信息

# curl status.xxx.com

参数详解:

Active connections: 1
表示正在处理的活动连接数目

server accepts handled requests
 12         12           12
server:表示重启动到现在nginx一共处理了12连接
accepts:表示重启动到现在一共成功创建了12个握手(请求丢失数目=accepts-server)
handle request:表示一共处理了12次请求。

Reading: 0 Writing: 1 Waiting: 0
Reading:读取到客户端的Header信息数。
writing:返回给客户端的Header信息数。
waiting:已经处理完正在等待下一次请求指令的驻留连接,在开启keepa-live时候这个值等于active-(reading+writing)。

Nginx的错误日志:
放置在main区块里面
指令:error_log file level;
Default: error_log logs/error_log error;
Nginx日志格式:
可以指定buffer ,压缩,flush频率
access_log logs/access_www.log main gzip buffer=32k flush=5s;
可以使用syslog服务发送到集中的服务器上去。
access_log syslog:server=address main
Nginx日志轮询:
轮询脚本

#!/bin/bash
set -e
set -x
Dateformat=`date +%Y%m%d` -d -1day
Basedir="/usr/local/nginx-1.6.3"
Nginxlogdir="$Basedir/logs"
Logname="access_www"
[ -d $Nginxlogdir ] && cd $Nginxlogdir||exit 1
[ -f ${Logname}.log ]||exit 1
/bin/mv ${Logname}.log ${Dateformat}_${Logname}.log
$Basedir/sbin/nginx -s reload
/bin/tar czvf ${Dateformat}_${Logname}.log.tar.gz ${Dateformat}_${Logname}.log

相关文章

  • 17《Nginx 入门教程》Nginx 的基础架构解析(上)

    1. Nginx 的进程模型 前面介绍 Nginx 时有介绍过 Nginx 的进程模型。Nginx 启动时首先启动...

  • 2020-03-21 Nginx介绍

    1. Nginx介绍 1.1 Nginx是什么 Nginx与Apache软件类似,Nginx(“engine x”...

  • nginx基础

    第一章 Nginx介绍 Nginx是什么? 我们为什么选择 Nginx 服务 Nginx重要特性 Nginx应用场...

  • day03.集群部署zookeeper【大数据教程】

    一、Nginx/keepalived/lvs的介绍 1.nginx 1.1.nginx简介 Nginx是一个自由、...

  • Nginx-1 yum安装

    Web服务器介绍nginx Nginx基本使用** 获取Nginx 关闭防火墙关闭selinux Nginx安装:...

  • 32-高性能WEB服务NGINX(一)

    本章内容◆ I/O模型◆ nginx介绍◆ nginx安装◆ nginx各种模块实现web服务◆ nginx实现f...

  • Nginx介绍

    1.Nginx最大的特点 1,静态小文件(1M),支持高并发,同时占用资源少。2,占用资源少3,配置简单,轻量。4...

  • Nginx 介绍

    Nginx Nginx(engine x)是一个高性能的代理服务器,主要作为HTTP server,HTTP re...

  • nginx介绍

    介绍 Nginx是一款轻量级的Web服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BS...

  • Nginx介绍

    1.Nginx常用命令(启动/重启/停止/测试配置文件/重新加载配置文件) -c:使用指定的配置文件而不是conf...

网友评论

    本文标题:Nginx介绍

    本文链接:https://www.haomeiwen.com/subject/ubvujftx.html