文章目录
Nginx的工作原理
Nginx作为web服务器:
Nginx是基于http协议实现的web服务器,通过epoll技术实现I/O多路复用,采用异步非阻塞实现高并发请求,异步非阻塞:1个master进程,2个work进程。
nginx是一个是高可用的http的web服务器和反向代理服务器,同时也是smtp简单邮件传输服务器
常用的配置路径
Nginx 部署-Yum,在不配置nginx的yum仓库时,默认的安装版本是1.12
版本1.12 没有默认的子配置文件
版本1.16 有默认的子配置文件
主配置文件路径是:vim /etc/nginx/nginx.conf
默认的虚拟主机配置:vim /etc/nginx/conf.d/default.conf
关于创建一个新的虚拟主机:
Nginx模块
状态连接模块: nginx_status
location /nginx_status {
stub_status; = 状态连接模块
allow all;
}
随机主页模块:random_index
location / {
#root /usr/share/nginx/html;
#index index.html index.htm;
root /app;
random_index on; on=打开 off=关闭
}
替换模块:sub_filter
sub_filter nginx 'QianFeng'; = 将nginx替换为QianFeng
sub_filter_once on;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
页面缓存模块: expires
location / {
root /app/tianyun.me;
index index.html index.htm;
expires 24h;
}
防盗链模块:valid_referers
location / {
root /a.com;
index index.html index.htm;
valid_referers none blocked白名单;
if ($invalid_referer) {
return 403; = 状态返回码 可以自定义
}
}
访问限制模块:ngx_http_limit_req_module
http {
limit_req_zone $binary_remote_addr zone=req_zone:10m rate=1r/s; 定义
server {
location / {
root /usr/share/nginx/html;
index index.html index.htm;
limit_req zone=req_zone; 引用
#limit_req zone=req_zone burst=5;
#limit_req zone=req_zone burst=5 nodelay;
}
}
}
访问控制模块:ngx_http_access_module
server {
allow 10.18.45.65;
allow 10.18.45.181;
deny all;
}