求教,如何让goaccess支持nginx中的$proxy
发布网友
发布时间:2022-04-08 09:17
我来回答
共2个回答
懂视网
时间:2022-04-08 13:38
GoAccess 是一个用来统计 Apache Web 服务器的访问日志的工具,可即时生成统计报表,速度非常快
查看的统计信息有:
统计概况,流量消耗等
访客排名
动态Web请求
静态web请求,如图片、样式表、脚本等。
来路域名
404 错误
操作系统
浏览器和搜索引擎
主机、DNS和IP地址
HTTP 响应代码
引荐网站
键盘布局
自定义显示
支持超大日志
2、安装
yum -y install glib2 glib2-devel ncurses ncurses-devel geoIP geoIP-devel
wget http://tar.goaccess.io/goaccess-0.9.3.tar.gz
tar -xzvf goaccess-0.9.3.tar.gz
cd goaccess-0.9.3/
./configure --enable-geoip --enable-utf8
make
make install
configure
Multiple options can be used to configure GoAccess. For a complete up- to-date list of configure options, run ./configure --help
--enable-debug
Compile with debugging symbols and turn off compiler optimizations.
--enable-utf8
Compile with wide character support. Ncursesw is required.
--enable-geoip
Compile with GeoLocation support. MaxMind‘s GeoIP is required.
--enable-tcb=<memhash|btree>
Compile with Tokyo Cabinet storage support. memhash will utilize Tokyo Cabinet‘s on-memory hash database. btree will utilize Tokyo Cabinet‘s on-disk B+ Tree database.
--disable-zlib
Disable zlib compression on B+ Tree database.
--disable-bzip
Disable bzip2 compression on B+ Tree database.
GoAccess Dependencies
Distro | NCurses | GLib >= 2.0.0 | GeoIP (optional) | Tokyo Cabinet (optional) |
Ubuntu/Debian |
libncursesw5-dev |
libglib2.0-dev |
libgeoip-dev |
libtokyocabinet-dev |
Fedora/RHEL/CentOS |
ncurses-devel |
glib2-devel |
geoip-devel |
tokyocabinet-devel |
Arch Linux |
ncurses |
glib2 |
geoip |
compile from source |
Gentoo |
sys-libs/ncurses |
dev-libs/glib:2 |
dev-libs/geoip |
dev-db/tokyocabinet |
3、用法
-f – 日志文件名
-b – 开启流量统计,如果希望加快分析速度不建议使用该参数
-s – 开启HTTP响应代码统计
-a – 开启用户代理统计
-e – 开启指定IP地址统计,默认禁用
例如
1、查看当天有多少个IP访问:
awk ‘{print $1}’ log_file|sort|uniq|wc -l
2、查看某一个页面被访问的次数:
grep “/index.php” log_file | wc -l
3、查看每一个IP访问了多少个页面:
awk ‘{++S[$1]} END {for (a in S) print a,S[a]}’ log_file
4、将每个IP访问的页面数进行从小到大排序:
awk ‘{++S[$1]} END {for (a in S) print S[a],a}’ log_file | sort -n
5、查看某一个IP访问了哪些页面:
grep ^111.111.111.111 log_file| awk ‘{print $1,$7}’
6、去掉搜索引擎统计当天的页面:
awk ‘{print $12,$1}’ log_file | grep ^”Mozilla | awk ‘{print $2}’ |sort | uniq | wc -l
7、查看2009年6月21日14时这一个小时内有多少IP访问:
awk ‘{print $4,$1}’ log_file | grep 21/Jun/2009:14 | awk ‘{print $2}’| sort | uniq |
goaccess
# goaccess -f /var/log/httpd/access_log
排除统计某来源IP
# goaccess -e 123.123.123.123 -f /var/log/httpd/access_log
检视Host详细资料的时候显示来自该Host的User-Agents资讯
# goaccess -a -f /var/log/httpd/access_log
产生HTML报表(静态报表)
# goaccess -a -f /var/log/httpd/access_log > result.html
只统计来自某IP的记录
# grep ^123.123.123.123 /var/log/httpd/access_log | goaccess
键盘操作
F1或h:帮助
F5 :刷新主界面
q:退出程序/当前窗口/折叠当前模块
o或Enter:展开选中的模块或窗口
0-9以及Shift + 0:将选中的模块或窗口激活
k和j:模块内部移动
c:修改配色
^f和^b:模块中上下滚屏
tab shift+tab:前后切换模块
s:模块内部排序选择
/:在所有模块中搜索(支持正则)
n:找到下个匹配
g和G:跳到第一项/最后一项
生成html
goaccess -f /var/log/apache2/access.log -a > report.html
热心网友
时间:2022-04-08 10:46
这里用虚拟机配置了下:
nginx 配置文件内容:
主要是这一句:
proxy_cache_path /www/ levels=1:2 keys_zone=Z:10m inactive=1m max_size=30g;
这一句定义一个区域,名字是 Z ,在内存中的空间为10MB ,硬盘中的最大空间为 30G;
inactive=1m 是,1分钟之后缓存失效 ,从新从源服务器请求
这里纠正一下,inactive=1m 如果缓存1分钟没人访问,nginx 会删除掉这些缓存
/usr/local/nginx/conf/nginx.conf
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
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"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
proxy_cache_path /www/ levels=1:2 keys_zone=Z:10m inactive=1m max_size=30g;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /www/;
#expires max;
#proxy_store on;
#proxy_store_access user:rw group:rw all:rw;
#proxy_temp_path /www/;
proxy_cache Z;
proxy_cache_valid 200 1m;
#expires max;
include proxy.conf;
if ( !-e $request_filename) {
proxy_pass http://192.168.1.199:45815;
}
}
#这里设置当 访问 /ajax/目录下的内容时候,直接从源服务器读取,主要用于ajax 的访问请求,要求实时的
location /ajax/ {
include proxy.conf;
if ( !-e $request_filename) {
proxy_pass http://192.168.1.199:45815;
}
}
#location ~.*\.(jpg|png|jpeg|gif)
#{
# expires max;
#}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443;
# server_name localhost;
# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_timeout 5m;
# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
/usr/local/nginx/conf/proxy.conf
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Accept-Encoding 'gzip';
client_max_body_size 100m;
client_body_buffer_size 256k;
proxy_connect_timeout 60;
proxy_send_timeout 60;
proxy_read_timeout 60;
proxy_buffer_size 512k;
proxy_buffers 8 512k;
proxy_busy_buffers_size 512k;
proxy_temp_file_write_size 512k;
一开始我就这样配置,认为可以成功了,结果发现动态文件无法被缓存,而html 文件可以被缓存,后来就到很多地方去问,
心想会不会是因为 文件 的 头信息或者Last-Modified
信息和 ETag 造成的,就去问,http://www.dewen.org/q/9769/nginx+%E5%A6%82%E4%BD%95%E7%BC%93%E5%AD%98%E5%8A%A8%E6%80%81%E9%A1%B5%E9%9D%A2%EF%BC%9F
发现果真如此,马上修改源服务器的动态文件,加入以下代码:
<%@ Page Language="C#" %>
<%
string date = Request.Headers.Get("If-Modified-Since");
if (date != null)
{
Response.StatusCode = 304;
Response.StatusDescription = "from cache";
return;
}
DateTime expDate = new DateTime(2037, 12, 31, 23, 55, 55);
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetExpires(expDate);
Response.Cache.SetMaxAge(expDate - DateTime.Now);
Response.Cache.SetLastModified(new DateTime(2000, 1, 1));
%>
<%=DateTime.Now.ToString()%>
然后发现就可以缓存动态文件了。至此,下一步我就可以用nginx 作为用户访问的 服务器了
转载仅供参考,版权属于原作者。祝你愉快,满意请采纳哦