标签归档:nginx

Nginx配合PHP简易鉴权-手札

PHP设置文件:

    if(strpos($_SERVER['HTTP_REFERER'],'explor')){
        header("Content-Type: application/octet-stream");
        header("X-Accel-Redirect: /hls/" . $_GET['file']);
    }

使用HTTP_REFFER中含有explor字段才可以内部跳转,这里可以加上SESSION或者COOKIE判断

Nginx 启用内部跳转:

    location /hls{
        internal;
        add_header Access-Control-Allow-Origin *;
        alias /home/wwwroot/your_web_path/public/video;
    }

默认直接访问/hls会被静止,必须使用内部跳转,然后重定向到资源位置 /home/wwwroot/your_web_path/public/video

nginx限速

主配置文件nginx.conf

limit_conn_zone $server_name zone=servers:10m;

网站文件配置

limit_conn servers 1000;
limit_rate_after 500k; 
limit_rate 50k;
limit_conn one 1;
limit_rate 300k;

python日志分析脚本

一个简单的python分析nginx日志的脚本,版本为python3。
脚本log.py

import os,re,sys
if len(sys.argv)<3:
    print("you must input your log file and anystr")
else:
    if os.path.isfile(sys.argv[1]):
        logfile=open(sys.argv[1],'r')
        alog=None
        if len(sys.argv)==4:
            alog=open(sys.argv[3],'w')
        for line in logfile:
            if re.findall(r''+sys.argv[2]+'',line):
                print(line)
                if alog:
                    alog.write(line)
        if alog:
            alog.close()
        logfile.close()
    else:
        print("no log file")

python3 log.py www.abc.com.log '\?s=' ax.log

www.abc.com.log 你的网站日志
‘?s=’正则匹配
ax.log匹配后的文件保持位置(非必需)

详情点击此处 maysrp/pylog