agent.conf

HSCSEC

agent.conf

nginx统一管理与封禁

封禁:仅封禁垃圾蜘蛛,不封禁搜索引擎

SSL管理:Let's encrypto证书申请,校验地址位"/"

报错页面:统一将报错页定向至/var/www/html/errors.html,可配合errors.html公益报错页使用。

ICON:统一将页面标志定向到/var/www/html/favicon.ico;

gzip为压缩传输,分为1-9级,等级越高,压缩率越大,占用CPU资源越多。

注意:akalog日志形式需要自行配置,描述见本文关于aka_logs日志格式描述。

location = /favicon.ico {
	alias /var/www/html/favicon.ico;
}
error_page 500 502 503 504 400 403 404 /errors.html;
location = /errors.html {
        alias  /var/www/html/errors.html;
}
location ^~ /.well-known/acme-challenge/{
        default_type "text/plain";
        root /;
}
if ($http_user_agent ~* "MJ12bot|Scrapy|python|AhrefsBot|BLEXBot|DotBot|^$") {
        return 403;
        break; 
}
gzip  on;
gzip_types text/plain application/javascript   application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png image/jpg;
gzip_disable "MSIE [1-6]\.";
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_comp_level 6;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log info;
access_log  /var/log/nginx/access_aka.log  aka_logs;

如何下载

mkdir -p /etc/nginx/conf.d/agent
wget --http-user=download@hscsec.cn  --http-passwd=HSC2019   https://download.hscsec.cn/nginx/agent.conf -O /etc/nginx/conf.d/agent/agent.conf

如果您不是第一次使用,可运行以下命令更新最新版本配置并应用。

wget --http-user=download@hscsec.cn  --http-passwd=HSC2019   https://download.hscsec.cn/nginx/agent.conf -O /etc/nginx/conf.d/agent/agent.conf && nginx -t && systemctl restart nginx

如何使用

将以下语句添加至server{}下即可。

	include conf.d/agent/agent.conf;

关于aka_logs

Nginx可自定义日志格式,以下为aka格式日志配置内容。如需使用,建议将以下配置复制到/etc/nginx/nginx.conf的http{}内

        log_format aka_logs
                '{"@timestamp":"$time_iso8601",'
                '"host":"$hostname",'
                '"server_ip":"$server_addr",'
                '"client_ip":"$remote_addr",'
                '"xff":"$http_x_forwarded_for",'
                '"domain":"$host",'
                '"url":"$uri",'
                '"referer":"$http_referer",'
                '"args":"$args",'
                '"upstreamtime":"$upstream_response_time",'
                '"responsetime":"$request_time",'
                '"request_method":"$request_method",'
                '"status":"$status",'
                '"size":"$body_bytes_sent",'
                '"request_body":"$request_body",'
                '"request_length":"$request_length",'
                '"protocol":"$server_protocol",'
                '"upstreamhost":"$upstream_addr",'
                '"file_dir":"$request_filename",'
                '"http_user_agent":"$http_user_agent"'
        '}';

Last updated