Nginx-headers-more-nginx-module
headers-more-nginx-module
headers-more-nginx-module 模块用于添加、修改或清除 请求/响应头,该模块不是nginx自带的,默认不包含该模块,需要另外安装。
Github地址:
GitHub - openresty/headers-more-nginx-module: Set, add, and clear arbitrary output headers in NGINX http servers
模块主要的指令
more_set_headers 用于添加、修改、清除响应头
more_clear_headers 用于清除响应头
more_set_input_headers 用于添加、修改、清除请求头
more_clear_input_headers 用于清除请求头
2.修改nginx web 服务器版本信息
1234567891011121314server { listen 80; server_name localhost; more_set_headers "Server: Web ...
Nginx-add header
add_header
Adds the specified field to a response header provided that the response code equals 200, 201 (1.3.10), 204, 206, 301, 302, 303, 304,307 (1.1.16, 1.0.13), or 308 (1.13.0).Parameter value can contain variables.
There could be several add_header directives.These directives are inherited from the previous configuration level if and only if there are no add_header directivesdefined on the current level.
官方文档的意思也就是在响应状态码成功时,add_header指令才生效,并且当前“作用域”下没有 add_header指令时,会向上层继承。
作用:使用add_h ...
Nginx-rewrite
nginx rewrite
rewrite模块即ngx_http_rewrite_module模块,主要功能是改写请求URI,是Nginx默认安装的模块。rewrite模块会根据PCRE正则匹配重写URI,然后发起内部跳转再匹配location,或者直接做30x重定向返回客户端。
rewrite 语法
1rewrite regex replacement [flag]
regex:表示正则匹配规则。
replacement:表示跳转后的内容。
flag:表示 rewrite 支持的 flag 标记。
flag标记说明:
last:本条规则匹配完成后,继续向下匹配新的location URL规则,一般用在server和 if 中。
break:本条规则匹配完成即终止,不再匹配后面的任何规则,一般使用在location中。
redirect:返回302临时重定向,浏览器地址会显示跳转后的URL地址。
permanent:返回301永久重定向,浏览器地址栏会显示跳转后的URL地址。
注:last和break最大的不同在于
break 是终止当前lo ...
Nginx-使用实例
通过阿里云免费SSL证书配置HTTPS
登录阿里云网页端,进入SSL证书模块,选择免费证书,创建证书,填写好相关信息后,提交审核.
审核通过后,下载证书,选择Nginx,可参考阿里云帮助手册,进行部署
把下载好的证书上传至服务器,可以在nginx相关目录中新建文件夹cert用于存放证书相关信息
然后,修改nginx的配置信息,可新建一个conf.d目录里面存放单独的配置文件
1234mkdir conf.dchmod 777 conf.d# 新建配置文件vim xxx.xxx.cn.conf
12345678910111213141516171819202122232425# 注意要保持server_name的值与之前申请的证书所填写的一致,不然会出现"您与此网站之间建立的连接并非完全安全"即证书域名和设置的域名不一致问题server { listen 443 ssl; server_name xx.xxxxx.cn; #需要将yourdomain.com替换成证书绑定的域名. ssl_certificate ../.. ...
Nginx-模块
参考文献
Nginx模块结构图
Nginx-学习笔记(一)
参考文献
深入理解Nginx模块开发与架构解析 陶辉
极客时间 Nginx核心知识150讲 陶辉
Nginx的优点
高并发,高性能
可扩展性好
高可用
热部署
BSD许可证
Nginx的三个应用场景
静态资源服务
通过本地文件系统提供服务
反向代理服务
Nginx的强大性能
缓存
负载均衡
API服务
OpenResty
Nginx的组成
Nginx二进制可执行文件
由各个模块源码编辑出的一个文件
nginx.conf配置文件
控制Nginx的行为
默认放置于/usr/local/nginx/conf, /etc/nginx或 /usr/local/etc/nginx。
access.log访问日志
记录每一条HTTP请求信息
error.log错误日志
定位问题
nginx.pid 进程ID文件
默认放置于/usr/local/nginx/logs或 /var/run
Nginx版本
开源免费的Nginx http://www.nginx.org
商业版的Nginx Plus http://www.nginx.com
...
Nginx-使用场景
参考文献
全面了解 Nginx 主要应用场景
彻底搞懂 Nginx 的五大应用场景
Nginx主要使用场景
反向代理
负载均衡
HTTP服务器(包含动静分离)
正向代理
反向代理
反向代理应该是Nginx使用最多的功能了,**反向代理(Reverse Proxy)**方式是指以代理服务器来接受Internet上的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到的结果返回给Internet上请求连接的客户端,此时代理服务器对外就表现为一个反向代理服务器.
简单来说就是真实的服务器不能直接被外部网络访问,所以需要一台代理服务器,而代理服务器能被外部网络访问的同时又跟真实服务器在同一个网络环境,当然也可能是同一台服务器,端口不同而已;
反向代理通过proxy_pass指令来实现.
1234567891011121314server { listen 80; server_name localhost; client_max_body_size 1024M; location / { p ...