GoAccess成功-希望互相帮助

时间:2019-07-09 06:48:26

标签: nginx-reverse-proxy nginx-config goaccess

此conf解决了一些问题,然后使goaccess正常工作,首先出现错误400,502 ... 希望这对其他用户有帮助。以为我不认为这是严格的权利,但确实有效。

我的基本环境是

  
      
  • ubuntu 18.04 LTS
  •   
  • nginx 1.17.1 [自配置,path = / root]
  •   
  • letencrypt
  •   
  • sshfs
  •   
  • goaccess [--enable-utf8 --enable-geoip = legacy --with-openssl]
  •   

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

全部。现在打开看起来像我的“ rp.test.com”的网址,您应该会看到类似的声音。(如果没有其他特殊条件)

goaccess runing

玩得开心!

PS:顺便说一句,希望有人可以改善上面的代码。

1 个答案:

答案 0 :(得分:2)

此解决方案/配置解决了我的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

全部。现在打开看起来像我的“ rp.test.com”的网址,您应该在下面看到类似的内容(如果没有其他特殊条件)。

运行:

goaccess running

  

注意:这是CROTEL的解决方案,最初发布于question,随后由社区成员转移到社区Wiki答案中,以符合Stack Overflow的Q / A格式