Nginx作为web服务器
为什么选择Nginx,nginx有诸多优点:
nginx是轻量级web服务器,支持AIO、mmap、event-driven,解决了c10k问题、虚拟主机、基于名字和IP访问、nginx平滑升级 、热部署、自定义日志格式、3XX 5XX错误代码重定向、重写url、支持http referer 使用防盗链(判断请求过来的url)、支持flv和mp4流、速度限制。
框架:
一个主进程master,多个子进程worker
支持sendfile/sendfile64
配置文件结构:
server{}:虚拟主机
location{}:
location /URI/ {
root “/web/htdocs”
}
location URI:对当前路径和自路径下的所有对象都生效,匹配范围大
location = URI:对当前路径生效,精确匹配指定路径,不包括子路径
location ~ URI {}:
location ~* URI {}:
模式匹配URI,此处的URI可以使用正则表达式,~区分字符大小写,~*不区分
location ^~ URI {}:不使用正则表达式
匹配优先级”=” > “/” “^~” > “~”
例子:
location = / {
[ configuration A ]
}
location / {
[ configuration B ]
}
location /documents/ {
[ configuration C ]
}
location ^~ /images/ {
[ configuration D ]
}
location ~* \.(gif|jpg|jpeg)$ {
[ configuration E ]
}
The “/” request will match configuration A, the “/index.html” request will match configuration B, the “/documents/document.html” request will match configuration C, the “/images/1.gif” request will match configuration D, and the “/documents/1.jpg” request will match configuration E.
一般配置
location / {
root /web/web1;
index index.html index.htm;
}

location /web2/ {
root /web;
index index.html index.htm;
}

介绍几个http相关模块:
- 访问控制法则:基于IP,Module ngx_http_access_module
deny
allow
location /web2/ {
root /web;
index index.html index.htm;
deny 192.168.31.85;
}

- 基于用户:Module ngx_http_auth_basic_module
location / {
satisfy any;
allow 192.168.1.0/32;
deny all;
auth_basic "closed site";
auth_basic_user_file conf/htpasswd;
}
location /web2/ {
root /web;
index index.html index.htm;
auth_basic "closed site";
auth_basic_user_file /etc/nginx/.users;
}
创建用户:
-c 第一次创建文件时使用:
# htpasswd -c -m /etc/nginx/.users tom
# htpasswd -m /etc/nginx/.users tom2

- 允许列出其文件:Module ngx_http_autoindex_module
找不到主页面时,默认拒绝访问:
location / {
root /web/web1;
index home.html;
}

location / {
root /web/web1;
index home.html;
autoindex on;
}

- 统计访问信息:Module ngx_http_stub_status_module
location /basic_status {
stub_status;
}
In versions prior to 1.7.5, the directive syntax required an arbitrary argument, for example, “stub_status on”.
访问:http://192.168.2.168/basic_status

当前处理活动的链接个数
已经接受的连接数 已经处理的连接数 已经处理的请求数
Reading
The current number of connections where nginx is reading the request header.
Writing
The current number of connections where nginx is writing the response back to the client.
Waiting
The current number of idle client connections waiting for a request.(长连接模式保持的个数)
- https访问:Module ngx_http_ssl_module
server {
listen 443 ssl;
server_name localhost;
ssl on;
ssl_certificate /etc/nginx/ssl/nginx.crt;
ssl_certificate_key /etc/nginx/ssl/nginx.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root /web/ssl;
index index.html index.htm;
}
}

- Module ngx_http_fastcgi_module
location ~ ^(.+.php)(.*)$ {
fastcgi_split_path_info ^(.+.php)(.*)$;
include fastcgi.conf;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
参见前面Zabbix系统搭建,就是一个很好LEMP应用的实践。
总结:
Nginx以其优秀的性能和提供的各种模块,作为web服务器越来越被多数企业选择,这里没有详细介绍Nginx作为web服务器相关的各个模块,大家可以参考官方文档或其他途径学习更多Nginx特性,官方文档http://nginx.org/en/docs/
Nginx作为web服务器的更多相关文章
- NGINX高性能Web服务器详解(读书笔记)
原文地址:NGINX高性能Web服务器详解(读书笔记) 作者:夏寥寥 第4章 Nginx服务器的高级配置 4.1 针对IPv4的内核7个参数的配置优化 说明:我们可以将这些内核参数的值追加到Linu ...
- Nginx是什么,有什么优点?为什么选择Nginx做web服务器软件?(经典经典)
1.基础知识 代理服务器: 一般是指局域网内部的机器通过代理服务器发送请求到互联网上的服务器,代理服务器一般作用在客户端.应用比如:GoAgent,FQ神器. 一个完整的代理请求过程为:客 ...
- 《Nginx高性能Web服务器》系列分享专栏
<Nginx高性能Web服务器>系列分享专栏 [作者:Poechant] Nginx是目前最流行的基于BSD-like协议.轻量级.高性能的HTTP服务器.反向代理服务器和电子邮件(SMT ...
- nginx高性能WEB服务器系列之九--nginx运维故障日常解决方案
nginx系列友情链接:nginx高性能WEB服务器系列之一简介及安装https://www.cnblogs.com/maxtgood/p/9597596.htmlnginx高性能WEB服务器系列之二 ...
- nginx高性能WEB服务器系列之八--nginx日志分析与切割
nginx系列友情链接:nginx高性能WEB服务器系列之一简介及安装https://www.cnblogs.com/maxtgood/p/9597596.htmlnginx高性能WEB服务器系列之二 ...
- nginx高性能WEB服务器系列之七--nginx反向代理
nginx系列友情链接:nginx高性能WEB服务器系列之一简介及安装https://www.cnblogs.com/maxtgood/p/9597596.htmlnginx高性能WEB服务器系列之二 ...
- nginx高性能WEB服务器系列之六--nginx负载均衡配置+健康检查
nginx系列友情链接:nginx高性能WEB服务器系列之一简介及安装https://www.cnblogs.com/maxtgood/p/9597596.htmlnginx高性能WEB服务器系列之二 ...
- nginx高性能WEB服务器系列之五--实战项目线上nginx多站点配置
nginx系列友情链接:nginx高性能WEB服务器系列之一简介及安装https://www.cnblogs.com/maxtgood/p/9597596.htmlnginx高性能WEB服务器系列之二 ...
- nginx高性能WEB服务器系列之四配置文件详解
nginx系列友情链接:nginx高性能WEB服务器系列之一简介及安装https://www.cnblogs.com/maxtgood/p/9597596.htmlnginx高性能WEB服务器系列之二 ...
随机推荐
- 集成支付宝钱包支付 iOS SDK 的方法与经验
下载 首先,你要想找到这个SDK,都得费点功夫.现在的SDK改名叫移动支付集成开发包了,下载页面在 这里 (http://t.cn/8ksiklD)的 “请点此下载集成开发包(http://t.cn/ ...
- 聊聊阻塞与非阻塞、同步与异步、I/O模型
1. 概念理解 在进行网络编程时,我们常常见到同步(Sync)/异步(Async),阻塞(Block)/非阻塞(Unblock)四种调用方式: 同步/异步主要针对C端: 同步: 所谓同步,就是在c端 ...
- “医疗信息化行业之中的联发科”- 我们在医疗行业中的定位及目标 想做一个面对中小企业的专业上游软件供应商 台湾联发科技颠覆掉的是一个封闭的手机产业系统 解决方案,即AgileHIS.NET数字化医院基础方案
“医疗信息化行业之中的联发科”- 我们在医疗行业中的定位及目标 我们做中国医疗信息化行业之中的联发科 ---我们在医疗行业中的定位及目标 从我个人来讲,我从2001年到现在这10年之间基本上一直在 ...
- Spring Boot加载配置文件
问题1:Spring如何加载配置,配置文件位置? 1.默认位置: Spring Boot默认的配置文件名称为application.properties,SpringApplication将从以下位置 ...
- iOS证书(.p12)和描述文件(.mobileprovision)申请
证书类型 使用场景 开发(Development)证书和描述文件 用于开发测试,在HBuilder中打包后可在真机环境通过Safari调试 发布(Distribution)证书和描述文件 用于提交Ap ...
- SharePoint 2013 Farm 安装指南——Least Privilege
写过很多关于SharePoint 2013 安装,这是第四篇.可能你会觉得为什么如此简单的安装至于花那么多精力去折腾吗.我的答案是肯定的.知识的积累不是一蹴而就的,而是循序渐进的去学习,每一个阶段都有 ...
- kafak manager + zookeeper + kafka 消费队列快速清除
做性能测试时,kafka消息队列比较长,让程序自己消费完毕需要等待很长时间.就需要快速清理kafka队列 清理方式把 这kafak manager + zookeeper + kafka 这些应用情况 ...
- iphone5刷机教程
如果不想麻烦可以在越狱之后添加源,cydia.china3gpp.com打ios7的补丁就可以了 机器为iphone5 美国sprint有锁版 1. 首先备份需要的程序和数据(把各种缓存的影片删掉再备 ...
- sudo: /etc/sudoers is owned by uid 755, should be 0
在ubuntu环境下, 想往/etc/sudoers中添加可以执行sudo操作的用户,使用root将/etc/sudoers的权限修改为755后,提示出现标题中的错误: 修正方法:将/etc/sudo ...
- Spring Security教程(八):用户认证流程源码详解
本篇文章主要围绕下面几个问题来深入源码: 用户认证流程 认证结果如何在多个请求之间共享 获取认证用户信息 一.用户认证流程 上节中提到Spring Security核心就是一系列的过滤器链,当一个请求 ...