1.nginx.conf文件说明:
server {
listen 80;
server_name www.oldzb.com;
location / {
root /usr/share/nginx/html;
autoindex on; --- 开启nginx站点目录索引功能,搭建文件共享服务器
charset utf-8; --- 修改目录结构中出现的中文乱码问题
}
location /zb {
root /usr/share/nginx/html;
index oldboy.html;
deny 192.168.223.0/24; --- 拒绝这个网段访问
allow 172.16.1.132; --- 允许这个IP访问
stub_status; --- 对网站进行监控
auth_basic "zhoubo"; --- 开启用户访问认证
auth_basic_user_file passwd/htpasswd; --- 用户认证密码,可以用htpasswd命令生成(htpasswd -bc htpasswd zhoubo 123456)
if ($host ~* "^oldzb.com$") {
rewrite ^/(.*) http://www.oldzb.com/$1 permanent;
} --- 输入oldzb.com会直接跳转到www.oldzb.com
return 404;---- 直接返回404页面
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
2.nginx日志说明:
$remote_addr 显示用户访问源IP地址信息
$remote_user 显示认证的用户名信息
[$time_local] 显示访问网站时间
"$request" 请求报文的请求行信息
$status 用户访问网站状态码信息
$body_bytes_sent 显示响应的数据尺寸信息
$http_referer 记录调用网站资源的连接地址信息(防止用户盗链)
$http_user_agent 记录用户使用什么客户端软件进行访问页面的 (谷歌 火狐 IE 安卓 iphone)
3.location详细配置:
Syntax: location [ = | ~ | ~* | ^~ ] uri { ... }
location @name { ... }
Default: —
Context: server, location
location = / { --- 精确匹配 优先级01 最高
[ configuration A ]
}
location / { --- 默认匹配 优先级04 最低
[ configuration B ]
}
location /documents/ { --- 按照目录进行匹配 优先级03
[ configuration C ]
}
location ^~ /images/ { --- 优先匹配/不识别uri信息中符号信息 优先级02
[ configuration D ]
}
location ~* \.(gif|jpg|jpeg)$ { --- 不区分大小写进行匹配 优先级03
[ configuration E ]
}