自定义日志服务
[root@localhost ~]# cat /apps/nginx/conf/conf.d/pc.conf
server {
listen 80;
server_name www.fxq.com;
error_log /data/nginx/logs/fxq-error.log info;
access_log /data/nginx/logs/fxq-access.log main;
location / {
root /data/nginx/html/pc;
index index.html;
}
}
要打开main
生成日志
页面不存在跳转服务
直接跳转到首页
[root@localhost ~]# cat /apps/nginx/conf/conf.d/pc.conf
server {
listen 80;
server_name www.fxq.com;
location / {
root /data/nginx/html/pc;
index index.html;
try_files $uri /index.html;
}
}
匹配uri目录下面的index.html文件
[root@localhost ~]# cat /apps/nginx/conf/conf.d/pc.conf
server {
listen 80;
server_name www.fxq.com;
location / {
root /data/nginx/html/pc;
index index.html;
try_files $uri $uri/index.html /index.html;
}
}
补全文件名
[root@localhost ~]# cat /apps/nginx/conf/conf.d/pc.conf
server {
listen 80;
server_name www.fxq.com;
location / {
root /data/nginx/html/pc;
index index.html;
try_files $uri $uri.html /index.html;
}
}
返回状态码
[root@localhost ~]# cat /apps/nginx/conf/conf.d/pc.conf
server {
listen 80;
server_name www.fxq.com;
location / {
root /data/nginx/html/pc;
index index.html;
try_files $uri =123;
}
}
长连接配置
keepalive_requests 3;
keepalive_timeout 65 65;
开启长连接后,返回客户端的会话保持时间为65s,单次长连接累计请求达到指定次数请求或65秒就会被断开,后面的65s为发送给客户端应答报文头部中显示的超时间设置为65s:如不设置客户端将不显示超时时间
使用telnet测试
telnet www.fxq.com 80
2次后断开
文件缓存
可配置在http,server,location
[root@localhost ~]# cat /apps/nginx/conf/conf.d/pc.conf
server {
listen 80;
server_name www.fxq.com;
open_file_cache max=10000 inactive=60s; #最⼤大缓存10000个⽂文件,⾮非活动数据超时时⻓长60s
open_file_cache_valid 60s; #每间隔60s检查⼀一下缓存数据有效性
open_file_cache_min_uses 5; #60秒内⾄至少被命中访问5次才被标记为活动数据
open_file_cache_errors on; #缓存错误信息
server_tokens off; #隐藏Nginx server版本。
location / {
root /data/nginx/html/pc;
index index.html;
allow 12.168.33.179;
}
}
状态页
基于nginx模块ngx_http_stub_status_module实现,在编译安装nginx的时候需要添加编译参数--with-http_stub_status_module,否则配置完成之后监测会是提示语法错误。
状态⻚页⽤用于输出nginx的基本状态信息:
输出信息示例例:
Active connections: 291
server accepts handled requests
16630948 16630948 31070465
上⾯面三个数字分别对应accepts,handled,requests三个值
Reading: 6 Writing: 179 Waiting: 106