Nginx 基础(二)

446 阅读1分钟

使用 GoAccess 监控 Nginx 日志


我使用的是 openResty,下面这是 openResty 中 nginx 文件夹的目录; nginx 的配置文件在 conf 中. 日志文件在 logs 文件夹中.

1j2129.png

GoAccess 安装


官网链接 https://goaccess.io/

  • 进入你需要安装的文件目录,下载源文件:wget tar.goaccess.io/goaccess-1.…
  • 解压到当前文件夹路径下:tar -xzf goaccess-1.3.tar.gz -C ./
  • 进入到解压目录:cd goaccess-1.3/
  • ./configure --enable-utf8 --enable-geoip=legacy
  • make
  • make install

执行完上面的命令以后,可能会出现下面的问题

configure: error: 
*** Missing development files for the GeoIP library

# 这是由于缺少一个库 GeoIP, 解决方法:
$ wget https://github.com/maxmind/geoip-api-c/releases/download/v1.6.11/GeoIP-1.6.11.tar.gz
$ tar -xzvf GeoIP-1.6.11.tar.gz
$ cd GeoIP-1.6.11
$ ./configure
$ make
# make install
# 解决方法:centOS --- yum install ncurses-devel; Ubuntu --- apt-get install
# 原因:因为使用了参数 --enable-utf8
libncursesw5-dev
configure: error: 
*** Missing development libraries for ncursesw

解决了上面的问题以后,重新执行 goaccess 的安装命令, 查看安装后版本信息 goaccess -V,如果无误,你会看到相关的版本信息.

GoAccess 配置


需要指定工作台文件的位置,这里可以设置在任意目录下,我把放在 nginx 的 /usr/local/openresty/nginx/html

在下面的启动命令中,logPath 就是 nginx logs 的目录,htmlPath 是你希望存放 html 文件的位置

 goaccess logPath/access.log -o htmlPath/report.html --real-time-html --log-format=COMBINED --ws-url=wss://url:7890/
location /report.html {
   alias /usr/local/openresty/nginx/html/report.html;
}

可能遇到的问题: --ws-url=wss://url:7890/ 如果不加这个参数,可能当你打开浏览器页面,会提示 wss 错误

  • 安装完成以后