Nginx 入门学习
什么是 Nginx
Nginx 是一款轻量级高性能的web 和 反向代理服务器,类似于Apache,也是一个 IMAP/POP3/SMTP (电子邮件)代理服务器。由俄罗斯程序设计师 Igor Sysoev开发;在高连接并发的情况下,Nginx能够支持高达 50000 个并发连接数的响应,是 Apache 服务器不错的替代品。
nginx做为HTTP服务器,有以下几项基本特性:
1. 处理静态文件,索引文件以及自动索引;打开文件描述符缓冲.
2. FastCGI和反向代理加速(无缓存),简单的负载均衡和容错.
3. 模块化的结构。包括gzipping, byte ranges, chunked responses,以及 SSI-filter等filter。如果由FastCGI或其它代理服务器处理单页中存在的多个SSI,则这项处理可以并行运行,而不需要相互等待。
4. 支持SSL 和 TLSSNI.
Nginx支持热部署。它的启动特别容易, 并且几乎可以做到7*24不间断运行,即使运行数个月也不需要重新启动。你还能够在不间断服务的情况下,对软件版本进行进行升级。
nginx是异步的,多个连接(万级别)可以对应一个进程。 apache是同步多进程模型,一个连接对应一个进程;
nginx的优势是处理静态请求,cpu内存使用率低,apache适合处理动态请求,所以现在一般前端用nginx作为反向代理抗住压力,apache 作为后端处理动态请求。
正向代理: 服务器代理客户端向服务端发送请求,并将数据分发给客户端,服务端无法知道客户端的信息
反向代理: 服务器代理服务端接收客户端的请求,并分发给服务器(分布式部署),反向代理隐藏了服务器的信息。
负载均衡: 客户端发送的、Nginx反向代理服务器接收到的请求数量,就是负载量。请求数量按照一定的规则进行分发到不同的服务器处理的规则,就是一种均衡规则,即代理服务器将请求按一定的规则分发的过程就是负载均衡。
安装
下载
点击进入官网下载 Windows版本,解压至 C盘
启动
双击 nginx.exe 或者 打开 CMD 进入 nginx 目录 输入 start nginx,如果启用防火墙,允许访问即可
常用命令
须使用CMD 进入跟目录才能使用 nginx
nginx -h //查看帮助
nginx -v // 查看版本
nginx -s stop //停用
nginx -s reload //重载配置,重启进程
nginx -s reopen //重启日志
代理配置
#user nobody;
#开启进程数 <=CPU数
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#进程号保存文件
#pid logs/nginx.pid;
events {
#每个进程最大连接数(最大连接=连接数x进程数)每个worker允许同时产生多少个链接,默认1024
worker_connections 1024;
}
http {
#文件扩展名与文件类型映射表
include mime.types;
#默认文件类型
default_type application/octet-stream;
#日志文件输出格式 这个位置相对于全局设置
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#请求日志保存位置
#access_log logs/access.log main;
#打开发送文件
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
#连接超时时间
keepalive_timeout 65;
#打开gzip压缩
#gzip on;
server {
#监听端口,默认是80端口
listen 80;
#监听域名
server_name localhost;
#charset koi8-r;
#nginx访问日志放在logs/host.access.log下,并且使用main格式(可以自定义格式)
#access_log logs/host.access.log main;
#如果没有location更明确的匹配访问路径的话,访问请求都会被该location处理
location / {
#root指定nginx的根目录为/usr/local/nginx/html
root html;
#默认访问文件,欢迎页先去html目录下找index.html,如果找不到再去找index.htm
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
#错误页面及其返回地址,错误码为500、502、503、504都会返回50.html错误页面
error_page 500 502 503 504 /50x.html;
#location后面是"="的话,说明是精确匹配
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
要监听多个端口和域名 可配置多个 server。
参考文章:
Nginx 中文文档
Nginx 相关介绍
深入浅出Nginx
Nginx 入门学习的更多相关文章
- Nginx 入门学习教程
昨天听一个前同事说他们公司老大让他去研究下关于Nginx 方面的知识,我想了下Nginx 在如今的开发技术栈中应该会很大可能会用到,所以写篇博文记录总结下官网学习教程吧. 1. 什么是Nginx? 我 ...
- nginx入门学习步骤(linux)
一.nginx下载(nginx-1.9.9) http://nginx.org/download/ 二.解压到指定文件夹 tar -zxvf 解压缩文件 三.设置配置信息 在nignx解压文件夹内执行 ...
- nginx入门学习
1.yum解决编译nginx所需的依赖包,之后你的nginx就不会报错了 yum install gcc patch libffi-devel python-devel zlib-devel bzip ...
- linux (08) nginx入门详解
一. nginx 入门 nginx 入门学习 web服务器软件 windows IIS服务器 linux nginx apache 收费lighthttp 公司的技术栈 收费版技术栈 apache ...
- nginx入门
1. 前言 Nginx是当前最流行的HTTP Server之一,根据W3Techs的统计,目前世界排名(根据Alexa)前100万的网站中,Nginx的占有率为6.8%.与Apache相比,Ngi ...
- nginx源代码学习资源(不断更新)
nginx源代码学习是一个痛苦又快乐的过程,以下列出了一些nginx的学习资源. 首先要做的当然是下载一份nginx源代码,能够从nginx官方站点下载一份最新的. 看了nginx源代码,发现这是一份 ...
- Nginx教程(一) Nginx入门教程
Nginx教程(一) Nginx入门教程 1 Nginx入门教程 Nginx是一款轻量级的Web服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like协议下发行.由 ...
- ElasticStack的入门学习
Beats,Logstash负责数据收集与处理.相当于ETL(Extract Transform Load).Elasticsearch负责数据存储.查询.分析.Kibana负责数据探索与可视化分析. ...
- nginx 入门实战
nginx入门实战 nginx 安装与卸载 下载安装 进入 http://nginx.org/en/download.html 下载自己想要的版本,我选择的stable版本 tar -zxvf ngi ...
随机推荐
- 基于Docker快速搭建ELK【华为云技术分享】
[摘要] 本文基于自建的Docker平台速搭建一套完整的ELK系统,相关的镜像直接从Docker Hub上获取,可以快速实现日志的采集和分析检索. 准备镜像 l 获取ES镜像:docker pull ...
- 让微信推送Jenkins构建消息
Jenkins作为开发必备之神器,各家大小公司都在使用.Jenkins自身内置了基于邮件推送构建结果的功能.但是随着移动互联网的发展,邮件这玩意已经越来越少使用了,是否有一种办法能把jenkins构建 ...
- javascript类数组
一.类数组定义: 而对于一个普通的对象来说,如果它的所有property名均为正整数,同时也有相应的length属性,那么虽然该对象并不是由Array构造函数所创建的,它依然呈现出数组的行为,在这种情 ...
- Vue - 组件通信之$attrs、$listeners
前言 vue通信手段有很多种,props/emit.vuex.event bus.provide/inject 等.还有一种通信方式,那就是 $attrs 和 $listeners,之前早就听说这两个 ...
- tensorflow mnist模块详解
tensorflow的官方文档是以mnist数据集为例子开始的.文档本身没有介绍tensorflow.contrib.learn.python.learn.datasets.mnist模块.要想用te ...
- vue2.5 + element UI el-table 导出Excel
安装依赖 npm install --save xlsx file-saver 新建excelHelper.js \src\utils\目录下新建excelHelper.js文件 import Vue ...
- Python 3 对象关系映射(ORM)
ORM 对象关系映射 Object Relational Mapping 表 ---> 类 字段 ---> 属性 记录 ---> 对象 # mysql_client.py impor ...
- 105道BAT最新Java面试题(MySQL+Redis+nginx+ookeeper+MongoDB)
MySQL面试题 1. 主键 超键 候选键 外键 2.数据库事务的四个特性及含义 3. 视图的作用,视图可以更改么? 4. drop,delete与truncate的区别 5. 索引的工作原理及其种类 ...
- java8新特性- 默认方法 在接口中有具体的实现
案例分析 在java8中在对list循环的时候,我们可以使用forEach这个方法对list进行遍历,具体代码如下demo所示 public static void main(String[] arg ...
- .net下DllImport的一个小问题
最近搞几个PInvoke几个DLL, 在.net 2.0下木有问题, 跑的很好 如下: [DllImport( "tjo.dll" )] private static extern ...