- nginx做网页实现下载功能
- 添加文件夹
mkdir /usr/local/scnginx8/html/download
- 修改配置文件/usr/local/scnginx8/conf/nginx.conf
添加 autoindex on;
- 重新刷新:nginx -s reload
- 效果图:
- 添加文件夹
- 状态统计
- 修改配置文件/usr/local/scnginx8/conf/nginx.conf
添加 location = /sc_status{
stub_status;
}
- 检查语法:nginx -t
- 重新加载:nginx -s reload
- 效果图
- 实验:把效果图中的各数据写进数据库
import requests import time import datetime import pymysql config = { "host": "127.0.0.1", "user": "root", "password": "123456", "database": "sc", "charset": "utf8" } db = pymysql.connect(**config) cursor = db.cursor() result=requests.get("http://192.168.85.153:8080/sc_status") while True: data=result.text.split() act= data[2] ser= data[7] acc= data[8] han=data[9] reading=data[11] writing=data[13] waiting=data[15] print(act,ser,acc,han,reading,writing,waiting) now_time = datetime.datetime.now() print(now_time, type(now_time)) now_time = now_time.strftime("%Y-%m-%d %H:%M:%S") sql = "INSERT INTO nginx_index(act,ser,acc, han,reading,writing,waiting) VALUES(%s,%s,%s,%s,%s,%s,%s)" cursor.execute(sql, (act, ser, acc, han, reading, writing, waiting)) db.commit() # 提交数据 time.sleep(10) db.close()
- 实验:把效果图中的各数据写进数据库
-
- Active connections:有多少人现在向你的服务器发动了3次握手
- 活跃的连接数量
- 系统会自动保持活跃65秒(未主动关闭网页)
keepalive_timeout 65;
- server::表示nginx启动到现在共处理了多少个连接
- accepts:表示nginx启动到现在共成功创建了多少次握手(备注:请求丢失数=握手数-连接数)
- worker_connections 2048:一个进程抗2048个线程
- handled requests::表示总共处理了多少次请求
- Reading:为nginx读取到客户端的Header信息数
- Writing:为nginx返回给客户端的Header信息数
- Waiting:为nginx已经处理完正在等待下一次请求指令的驻留连接,在开启keep-alive的情况下。这个值等于active - (Reading+Writing)
- keep-alive:服务器在等待65秒内现在未发送请求客户机发送下一次请求
- Active connections:有多少人现在向你的服务器发动了3次握手
- 修改配置文件/usr/local/scnginx8/conf/nginx.conf
- pv(page view):页面浏览量
- 通常是衡量一个网络新闻频道或网站甚至一条网络新闻的主要指标。
- 状态统计加密认证:
- htpasswd命令
- 安装:yum install httpd-tools
- 加状态统计配置:/usr/local/scnginx8/conf/nginx.conf
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" "$connections_active" "$connections_writing" "$connections_waiting"';
access_log logs/access.log main;
- 加加密认证配置/usr/local/scnginx8/conf/nginx.conf
location = /sc_status{
stub_status;
auth_basic "sanchuang status";
auth_basic_user_file conf/htpasswd; #htpasswd是存放认证用户名和密码信息的文件
}
error_page 404 /404.html;
- 加用户:[root@localhost conf]# htpasswd -c /usr/local/scnginx8/conf/htpasswd xzz
- 检查:nginx -t
- 刷新:nginx -s reload
- htpasswd命令