0

我需要配置 Nginx 以使 Goaccess 工作。

我的环境是:

  • Ubuntu 18.04 LTS
  • Nginx 1.17.1 [ 自配置 , path=/root ]
  • 让我们加密
  • sshfs
  • goaccess [ --enable-utf8 --enable-geoip=legacy --with-openssl ]

由于这是一个自我回答的问答,我不包括我失败的尝试,而是发布我的解决方案。随意编辑它或发布另一个改进当前代码的答案

4

1 回答 1

3

此解决方案/配置解决了我的 400 和 502 错误

nginx conf【关键点】

upstream goaccess {
    server localhost:7890;
    keepalive 60;
}

server {
    listen 443 ssl; 
    ssl_certificate /etc/letsencrypt/live/test.com/fullchain.pem; 
    ssl_certificate_key /etc/letsencrypt/live/test.com/privkey.pem; 
    include /etc/letsencrypt/options-ssl-nginx.conf; 
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
    server_name rp.test.com;
    root  /var/www/goaccess;
    index  index.html;
    location / {
            try_files $uri  $uri/ @goaccess;
            alias /var/www/goaccess/;
            index  index.html;
            proxy_set_header Upgrade $http_upgrade;
            proxy_buffering on;            
            proxy_set_header Connection "Upgrade";
            proxy_connect_timeout 600s;
            proxy_send_timeout 600s;
            proxy_read_timeout 600s;
            proxy_temp_path  /var/nginx/proxy_temp;
    }

    location @goaccess{
            proxy_pass http://goaccess;
    }

}

goaccess [goaccess.sh]

#!/bin/sh
goaccess  /root/test2_nginx_log/www.test2.com_access.log -o /var/www/goaccess/index.html --real-time-html --origin=https://rp.test.com --addr=0.0.0.0 --port=7890 --ws-url=wss://rp.test.com --ssl-cert=/etc/letsencrypt/live/test.com/fullchain.pem --ssl-key=/etc/letsencrypt/live/test.com/privkey.pem  --time-format=%H:%M:%S --date-format=%d/%b/%Y --log-format=COMBINED

sshfs [run_sshfs.sh]

#!/bin/sh
if [ $(mount | grep 'root@111.111.111.xxx:/data/log/server/nginx' | wc -l) -ne 1 ]
then
    echo 'yourpassword' | sshfs root@111.111.111.xxx:/data/log/server/nginx /root/test2_nginx_log -o password_stdin,allow_other
else
    exit 0
fi

最后,检查 goaccess 的这个 sh 是否正在运行,并且挂载是否在线,然后重新启动它。

检查并重新启动 [ cr.sh ]

#!/bin/bash
if pgrep -x "goaccess" > /dev/null 
then
    clear ;
    echo "goaccess is running!"
    sleep 1
    echo "now cutting down goaccess...please wait"
    sleep 2
    kill `pgrep goaccess`
    echo "cut down done"
    sleep 1
    echo "now check mount test2 nginx log folder..."
    cd /root/ && ./run_sshfs.sh
    sleep 2
    echo "mount done"
    sleep 1
    echo "now restart goaccess..."
    cd /root/ && sudo nohup ./goaccess.sh > goaccess.log 2>&1 &
    sleep 2
    echo "goaccess was restarting success!"
    sleep 1
    echo "now all done!"
    exit 1
else
    clear ;
    echo "goaccess is down!"
    sleep 1
    echo "now check mount test2 nginx log folder..."
    cd /root/ && ./run_sshfs.sh
    sleep 2
    echo "mount done"
    sleep 1
    echo "now start goaccess..."
    cd /root/ && sudo nohup ./goaccess.sh > goaccess.log 2>&1 &
    sleep 2
    echo "goaccess was starting success!"
    sleep 1
    echo "now all done!"
fi

就这些。现在打开你的 url,它看起来像我的 'rp.test.com' 你应该在下面看到类似的东西(如果没有任何其他特殊情况)。

跑步:

goaccess 运行

注意:这是CROTEL的解决方案,最初发布有问题,随后由社区成员移至社区 wiki 答案以符合 Stack Overflow 的 Q/A 格式

于 2019-08-21T10:21:34.940 回答