1

I'm trying to make a CGI script (for nginx) that outputs an html page containing the usage statistics for my server. I'm using goaccess 0.7.1 and CentOS 5 x86.

I've configured nginx to run my bash script (stats.sh) for requests on port 8080.

The bash script looks like this:

#!/bin/bash

cat /var/log/nginx/mydomain.access.log | goaccess -a > stats.html

echo Content-Type: text/html
echo Content-Length: $(stat -c%s stats.html)
echo
cat stats.html

When I run ./stats.sh, everything works fine. It prints a bunch of html code in the console window, and if I open stats.html, I see a bunch of html code.

THE PROBLEM IS, when I try to access http://www.mydomain.com:8080/, I just get a blank page. Now when I open stats.html on the server, it's completely empty.

I've confirmed the following permissions:

  • stats.sh: -rwxr-xr-x
  • stats.html: -rw-rw-rw-
  • goaccess: -rwxr-xr-x

I also know that CGI is working properly because if I modify stats.sh to only output the contents of stats.html (without writing to the file), it works fine when I hit http://www.mydomain.com:8080/; it just sends whatever data was in stats.html from before. So something is going wrong with calling goaccess in a CGI script. Does anyone know why?

UPDATE

I also tried this:

echo "<!DOCTYPE hmtl><html><body>TEST</body></html>" > stats.html

and it works fine when I hit http://www.mydomain.com:8080/, so something is going wrong when running goaccess from FastCGI.

I also tried specifying the full path to goaccess (/usr/local/bin/goaccess):

/var/log/nginx/mydomain.access.log | /usr/local/bin/goaccess -a >stats.html 2>stats.err

but this also did not work.

  • Sounds like permissions issue, did you check your /var/log/nginx/nginx_error.log? – Kayla Aug 8 '14 at 3:04
  • It doesn't show anything from my :8080 request. The last entry is: 014/08/07 20:05:51 [error] 24993#0: *610 access forbidden by rule, client: x.x.x.x, server: _, request: "GET /manager/html HTTP/1.1", host: "x.x.x.x:8080". I don't have a page called /manager/html, nor did I ever request it, so I assume this is from a crawler. All of the errors from the last 2 days are similar to this one. – AJ Richardson Aug 8 '14 at 3:45
  • I tried your script on Apache (CGI), first it wasn't writing anything to stats.html (blank page), I did chmod a+rwx /usr/lib/cgi-bin and it worked fine. I'll see if I can fire up an nginx instance and test it. – Kayla Aug 8 '14 at 3:55
  • 1
    Perhaps writing the goaccess stderr log to a file can help clear things up: goaccess -a >stats.html 2>stats.err – brm Aug 8 '14 at 6:51
  • I tried adding the 2>stats.err part, but it doesn't generate the stats.err file at all when I run it from FastCGI. If I run the bash script manually, it generates stats.err as an empty file. – AJ Richardson Aug 26 '14 at 2:19
1

mydomainI finally got it to work! The main problem was my .goaccessrc file. I had foolishly created this file in /root, so obviously non-root users could not read it. I moved it to /etc and it works fine now. Here is the final code for my bash file:

#!/bin/bash

cat /var/log/nginx/mydomain.access.log | /usr/local/bin/goaccess -a -p /etc/.goaccessrc >stats.html 2>stats.err

echo Content-Type: text/html
echo Content-Length: $(stat -c%s stats.html)
echo
cat stats.html

Make sure to run chmod 666 stats.err.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.