功能 说明 配置语法 配置位置 配置举例 结果验证 备注
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. [b0044] numpy_快速上手

    1 概念理清 2 创建数组 2.1 f1= np.array( [ [1,2,3,4], [2,3,4,5], [3,4,5,6] ]) 其他代码 a= np.array([ [ [3.4,5,6,8 ...

  2. JavaScript 是如何运行的?

    摘要: 理解JS执行原理. 原文:JavaScript 是如何运行的? 作者:hengg Fundebug经授权转载,版权归原作者所有. 什么是JavaScript? 我们来确认一下JavaScrip ...

  3. rsync nfs web01总结

    目录 rsync nfs web01总结 要求 部署rsync服务端(172.16.1.41) 部署rsync客户端(172.16.1.31.172.16.1.7) 部署web代码 NFS服务端部署 ...

  4. 使用VS Code开发纸壳CMS自动编译主题压缩CSS,JS

    Visual Studio Code (简称 VS Code / VSC) 是一款免费开源的现代化轻量级代码编辑器,支持语法高亮.智能代码补全.自定义热键.括号匹配.代码片段.代码对比 Diff.GI ...

  5. JVM-1-HotSpot server client

    64位JDK 默认只能工作在Server模式下 是无法切换到Client模式的   Hot Spot虚拟机Server

  6. 【Autoit】Autoit 使用

    一.Autoit 上传文件. 1.常用语法 - WinActivate("title")         聚焦到指定活动窗口 - ControlFocus ( "titl ...

  7. MSYQL主从复制-Gtid方式

    目录 1.MYSQL主从复制-Gtid方式 1.环境准备 2.Master配置 3.Slave配置 4.报错&解决 我叫张贺,贪财好色.一名合格的LINUX运维工程师,专注于LINUX的学习和 ...

  8. 201871010124 王生涛《面向对象程序设计JAVA》第一周学习总结

    项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://edu.cnblogs.com/campus/xbsf/ ...

  9. LINUX上安装JDK+tomcat+mysql操作笔记

    1.环境准备: 1-1.centos 64位(本人的虚拟机安装此系统),安装步骤和网络配置已经在前两篇记录. 1-2.JDK 版本1.8 1-3.tomcat压缩包 1-4.CRT远程连接工具(可用其 ...

  10. acwing 651. 逛画展

    地址 https://www.acwing.com/problem/content/653/ 博览馆正在展出由世上最佳的 M 位画家所画的图画. wangjy想到博览馆去看这几位大师的作品. 可是,那 ...