功能 说明 配置语法 配置位置 配置举例 结果验证 备注
rewrite

跳转重定向
(不同于代理的跳转重定向,此处nginx不是代理服务器,而是本身就是web服务器)

rewrite 正则表达式 replacement[flag] server、location、if一级来配置

1、
location /down {
rewrite ^/down http://www.cctv.com permanent;
}

2、
location / {
rewrite ^/down /test/abc.html permanent;
root /opt/work;
}

1、访问http://Nginx地址/down时将跳转至http://www.cctv.com
2、访问http://Nginx地址/down时将跳转至http://Nginx地址/test/abc.html

正则表达式中()用于匹配括号之间的内容,通过$1,$2调用

flag标志位:
last:停止rewrite检测
break:停止rewrite检测
redirect:返回302临时重定向,地址栏会显示跳转后的地址
permanent:重返301永久重定向,地址栏会显示跳转后的地址(浏览器会永远记住,即使nginx服务器关闭了也还是会跳转至其他网页)(IE是这样的,但是搜狗浏览器收到301依然当做临时重定向处理)

rewrite加在不同位置时的优先级规则:server > location

SSL  提供HTTPS服务

ssl on|off
ssl_certificate file
ssl_certificate_key file

http、server这一级来配置

server{
listen 443;
server_name hk.com;

keepalive_timeout 100; ===>优化之使用长连接,100s

ssl on;
ssl_certificate /etc/nginx/ssl_key/hk1.crt;
ssl_certificate_key /etc/nginx/ssl_key/hk.key;

ssl_session_timeout 10m; ===>优化之SSL会话过期,10分钟
ssl_session_cache shared:SSL:10m; ===>优化之使用SSL缓存,大小为10M,可以存储大约8k到10k的会话
location / {
root /opt/app/code;
index index.html index.htm;
}
}

 

证书生成步骤(测试使用,生产环境肯定需要向权威CA厂商购买证书):

一、生成秘钥
openssl genrsa -des3 -out hk.key 1024
-des3:选择3des算法
1024:加密位数

二、生成证书
openssl req -days 36500 -x509 -sha256 -nodes -newkey rsa:2048 -keyout hk.key -out hk1.crt
-days:证书有效期
-x509:选择hash算法
rsa:2048:选择2048位加密
-keyout:key文件
-out:输出结果

苹果终端对服务端的要求:
1、服务器所有的连接使用TLS1.2以上的版本(openssl 1.0.2)
2、HTTPS证书必须使用SHA256以上的哈希算法签名
3、HTTPS证书必须使用RSA 2048位或ECC 256位以上公钥算法
4、使用前向加密技术

try_files 相当于if语句(如果这个路径下找不到则匹配另一个location) try_files $uri @其他location location一级来配置

location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri @code1;
}
location @code1 {
proxy_pass http://www.cctv.com;
}

此时访问http://nginx服务器/1.html时会先去/usr/share/nginx/html/目录找,
如果这个目录没有目标文件则匹配 @code1 这个location

测试时候发现location里面有try_files后index语句将失效,即访问http://nginx服务器/时
也会被导向@code1

 worker_processes  制定nginx的work进程数(不包含manage进程)  worker_processes 进程数  最开头那级来配置  worker_processes 10    建议和物理CPU核心数相同
 worker_rlimit_nofile   修改nginx最大句柄  worker_rlimit_nofile 句柄数  最开头那级来配置,和worker_processes  1;一级  worker_rlimit_nofile 65535;  

文件句柄的理解:程序打开一个本地文件产生一个文件句柄,默认操作系统只允许一个应用程序打开最多1024个文件

感觉只有nginx做web服务器时才需要调文件句柄,因为做反向代理的时候也不总是打开本地文件啊

linux修改文件句柄最大数(默认为1024):
vi /etc/security/limits.conf
root soft nofile 65535
root hard nofile 65535
* soft nofile 25535
* hard nofile 25535

CPU亲和 将所有进程均匀的分布在各个cpu核心上 worker_cpu_affinity auto; 最开头那级来配置,和worker_processes  1;一级

user nginx;
worker_processes 24;
worker_cpu_affinity auto;

[root@localhost conf.d]# ps -eo pid,args,psr | grep [n]ginx
9062 nginx: master process nginx 19
9371 nginx: worker process 0
9372 nginx: worker process 1
9373 nginx: worker process 2
9374 nginx: worker process 3
9375 nginx: worker process 4
9376 nginx: worker process 5
9377 nginx: worker process 6
9378 nginx: worker process 7
9379 nginx: worker process 8
9380 nginx: worker process 9
9381 nginx: worker process 10
9382 nginx: worker process 11
9383 nginx: worker process 12
9384 nginx: worker process 13
9385 nginx: worker process 14
9386 nginx: worker process 15
9387 nginx: worker process 16
9388 nginx: worker process 17
9389 nginx: worker process 18
9390 nginx: worker process 19
9391 nginx: worker process 20
9392 nginx: worker process 21
9393 nginx: worker process 22
9394 nginx: worker process 23

没有配置worker_cpu_affinity auto;时的CPU占用情况:
[root@localhost conf.d]# ps -eo pid,args,psr | grep [n]ginx
9062 nginx: master process nginx 22
9406 nginx: worker process 5
9407 nginx: worker process 0
9408 nginx: worker process 9
9409 nginx: worker process 2
9410 nginx: worker process 1
9411 nginx: worker process 3
9412 nginx: worker process 11
9413 nginx: worker process 0
9414 nginx: worker process 12
9415 nginx: worker process 6
9416 nginx: worker process 2
9417 nginx: worker process 5
9418 nginx: worker process 15
9419 nginx: worker process 9
9420 nginx: worker process 17
9421 nginx: worker process 0
9422 nginx: worker process 7
9423 nginx: worker process 2
9424 nginx: worker process 8
9425 nginx: worker process 9
9426 nginx: worker process 5
9427 nginx: worker process 0
9428 nginx: worker process 6
9429 nginx: worker process 2

nginx高级用法的更多相关文章

  1. nginx高级用法汇总

    1,nginx限制IP访问,允许IP访问 1.1 模块:nginx_http_access_module 注意:检测顺序是按配置顺序进行的,匹配首条规则将会被使用,所以要注意在配置文件配置的顺序. a ...

  2. redis的Linux系统安装与配置、redis的api使用、高级用法之慢查询、pipline事物

    今日内容概要 redis 的linux安装和配置 redis 的api使用 高级用法之慢查询 pipline事务 内容详细 1.redis 的linux安装和配置 # redis 版本选择问题 -最新 ...

  3. Visual Studio 宏的高级用法

    因为自 Visual Studio 2012 开始,微软已经取消了对宏的支持,所以本篇文章所述内容只适用于 Visual Studio 2010 或更早期版本的 VS. 在上一篇中,我已经介绍了如何编 ...

  4. SolrNet高级用法(分页、Facet查询、任意分组)

    前言 如果你在系统中用到了Solr的话,那么肯定会碰到从Solr中反推数据的需求,基于数据库数据生产索引后,那么Solr索引的数据相对准确,在电商需求中经常会碰到菜单.导航分类(比如电脑.PC的话会有 ...

  5. sqlalchemy(二)高级用法

    sqlalchemy(二)高级用法 本文将介绍sqlalchemy的高级用法. 外键以及relationship 首先创建数据库,在这里一个user对应多个address,因此需要在address上增 ...

  6. Solr学习总结(六)SolrNet的高级用法(复杂查询,分页,高亮,Facet查询)

    上一篇,讲到了SolrNet的基本用法及CURD,这个算是SolrNet 的入门知识介绍吧,昨天写完之后,有朋友评论说,这些感觉都被写烂了.没错,这些基本的用法,在网上百度,资料肯定一大堆,有一些写的 ...

  7. 再谈Newtonsoft.Json高级用法

    上一篇Newtonsoft.Json高级用法发布以后收到挺多回复的,本篇将分享几点挺有用的知识点和最近项目中用到的一个新点进行说明,做为对上篇文章的补充. 阅读目录 动态改变属性序列化名称 枚举值序列 ...

  8. Jquery remove 高级用法

    Jquery remove 高级用法 html 代码 <div class="file-image">abc1111</div><div class= ...

  9. Newtonsoft.Json高级用法(转)

    手机端应用讲究速度快,体验好.刚好手头上的一个项目服务端接口有性能问题,需要进行优化.在接口多次修改中,实体添加了很多字段用于中间计算或者存储,然后最终用Newtonsoft.Json进行序列化返回数 ...

随机推荐

  1. oracle体系结构简介

    oracle体系结构简介 一.物理存储结构    1.数据文件       存放数据库数据,以dbf为扩展名.将数据放在多个数据文件中,       再将数据文件分放在不同的硬盘中,可以提高存取速度. ...

  2. 网络编程~~~osi五层协议

    物理层 / 数据链路层 / 网络层 / 传输层 / 应用层(表示层/会话层) 一 物理层 物理层指的就是网线,光纤, 双绞线等物理传输介质 物理层发送的是数据(比特流) 二 数据链路层 数据链路层对数 ...

  3. Error 1327 Invalid Drive 的解决办法

    出现场景:     当我在安装STM32公司的 STM32 ST-LINK Utility v4.5.0 软件时,弹出了这个错误.弹框的内容大体是说找不到D盘,这里忘记截图了. 我的电脑的硬盘是我另一 ...

  4. kubernets过滤pod标签(labels)

    版权声明:本文为博主原创文章,支持原创,转载请附上原文出处链接和本声明. 本文地址:https://www.cnblogs.com/wannengachao/p/12074399.html 1.查看p ...

  5. TOMCAT修改默认端口(8080端口)

    在工作中,有可能需要在一台服务器上同时部署两个或两个以上的tomcat(服务器性能够好), 那么就需要修改其中的一个的端口号才能使得两个同时工作,总共需要修改3个地方: 1.首先到安装目录(或者解压目 ...

  6. 子传父flase注意点

    1==>在子传递数据给父亲的时候, closeBottom(){ this.$emit("closeBottom",false) } false不加引号. 2==>

  7. vue项目搭建及创建、目录结构、项目启动、全局配置

    Vue项目环境搭建 """ node ~~ python:node是用c++编写用来运行js代码的 npm(cnpm) ~~ pip:npm是一个终端应用商城,可以换国内 ...

  8. verilog 基础知识

    mealy型状态机的下一状态和输出取决于当前状态和当前输入: moore型状态机的下一状态和输出取决于当前状态和当前输入,但其输出仅取决于现在的状态: 基本门原语的输出端口必须写在端口列表的前面,基本 ...

  9. 解决问题:Red Hat Enterprise Linux 7 64 位 虚拟机安装后无法启动图形化

    原因: 1.系统在创建时,没有安装图形化 2.系统在安装后,有降低内存的操作,内存过低无法启动桌面,以及其他 就原因一进行图形化安装: 1.VMware挂载Red Hat Enterprise Lin ...

  10. Linux学习笔记-第19天 结束了。突然感觉配置一个服务好简单的样子

    课程结束了,这本书又过了一遍,感觉学习到了不少的新知识.虽然整个过程老师讲的有点仓促,但回头想想身处于这个知识大爆炸的时代,学习不单要追求知识面宽广,更需要注重学习的效率,某种角度来讲,这也是一种鞭策 ...