Last active
July 15, 2016 14:22
-
-
Save orangle/f094a38a9ef0a9fe9dc4 to your computer and use it in GitHub Desktop.
使用nginx post_action参数来统计文件下载情况,从而统计用户下载文件完整性
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
#-*- coding:utf-8 -*- | |
############################ | |
#File Name: counting_file.py | |
#Author: orangleliu | |
#Mail: [email protected] | |
#Created Time: 2015-03-11 16:41:05 | |
#License: MIT | |
############################ | |
''' | |
nginx统计用户下载文件字节 nginx配置文件 | |
location / { | |
limit_rate 20k; | |
post_action @afterdownload; | |
} | |
location @afterdownload { | |
proxy_pass http://127.0.0.1:8888/counting?FileName=$uri&ClientIP=$remote_addr&body_bytes_sent=$body_bytes_sent&status=$request_completion; | |
internal; | |
} | |
''' | |
from flask import Flask, request | |
app = Flask(__name__) | |
@app.route("/counting") | |
def counting(): | |
req = request.args.get("FileName") | |
clientip = request.args.get("ClientIP") | |
size = request.args.get("body_bytes_sent") | |
status = request.args.get("status") | |
print "request ", req | |
print "ip ", clientip | |
print "size ", size | |
print "status ", status | |
return "ok" | |
if __name__ == "__main__": | |
app.run(port=8888, debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!