0
点赞
收藏
分享

微信扫一扫

【系统部署知识汇总】第5章—— nginx默认网站


Nginx 默认⽹站

• 实验机器: Vmware 虚拟机 2核4G
• ⽹卡:桥接
• 系统:centos7.5
• 防⽕墙:关闭
• Selinux:关闭
• ⽹段:192.168.10.0/24

主机名 IP ⻆⾊
Master.ayitula.com 192.168.10.40 主分发器
Backup.ayitula.com 192.168.10.41 备分发器
Web01.ayitula.com 192.168.10.42 数据服务器1
Web02.ayitula.com 192.168.10.43 数据服务器2

Nginx默认⽹站 01

Nginx默认⽹站
当Nginx配置⽂件中有且只有⼀个Server的时候,该Server就被Nginx认为是默认⽹站,所有发给Nginx服务器80端⼝的数据都会默认给该Server.

server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}

Nginx⽬录访问控制 02

Nginx⽬录访问权限

location /a {
allow 192.168.1.0/24;
deny all;
#return 404;
return http://www.jd.com;
}

Nginx登陆验证 03

Nginx登陆认证

 auth_basic
语法: auth_basic string | off;
默认值: auth_basic off;

auth_basic_user_file file;

location /b {
auth_basic ”登陆验证";
auth_basic_user_file /etc/nginx/htpasswd;
}

⽇志管理 04

⽇志格式
Nginx访问⽇志主要有两个参数控制

  1. log_format #⽤来定义记录⽇志的格式(可以定义多种⽇志格式,取不同名字即可)

log_format log_name string

  1. access_log #⽤来指定⽇⾄⽂件的路径及使⽤的何种⽇志格式记录⽇志

access_log logs/access.log main;

Log_format格式变量
log_format格式变量:

200、301、404等
$body_bytes_sent #服务器发送给客户端的响应body字节数
$http_referer #记录此次请求是从哪个连接访问过来的,可以根据该参数进⾏防盗链设置。
$http_user_agent #记录客户端访问信息,例如:浏览器、⼿机客户端等
$http_x_forwarded_for #当前端有代理服务器时,设置web节点记录客户端地址的配置,此参数⽣效的前提是代理服务器也要进⾏相关的x_forwarded_for设置

⽇志⾃定义
⾃定义⽇志格式为json

log_format main_json '{"@timestamp":"$time_local",'
'"client_ip": "$remote_addr",'
'"request": "$request",'
'"status": "$status",'
'"bytes": "$body_bytes_sent",'
'"x_forwarded": "$http_x_forwarded_for",'
'"referer": "$http_referer"'
'}’;

access_log logs/access_json.log main_json;

防盗链 05

防盗链

location /images/ {
alias /data/images/;
# 针对哪些refer规则放行请求
valid_referers none blocked *.ayitula.com;
if ($invalid_referer) {
return 403;
}
}


举报

相关推荐

0 条评论