DirectAdmin Knowledge Base and Support

DirectAdmin is a web panel for a simple administration of both virtual and dedicated servers. DirectAdmin is faster, safe and more powerful than any other CP. And we know how to customize and support it.

I want AwStats to read nginx logs instead of Apache

| 13:02:48 12.11.2015

If you use nginx+apache and awstats, and stats shows too low values of used bandwidth, and in directadmin you see the bandwidth usage is much higher than in Awstats. Here is why this happens.

This all is due to how nginx proxies requests with the help of X-Accel to apache when you use nginx+apache on directadmin server. 

X-accel allows for internal redirection to a location determined by a header returned from a backend.

This allows you to handle authentication, logging or whatever else you please in your backend and then have NGINX handle serving the contents from redirected location to the end user, thus freeing up the backend to handle other requests. This feature is commonly known as X-Sendfile.

This feature differs a bit from standard NGINX modules as it does not rely on directives but rather handles headers from upstream in a special way. The way it works is that you send the header x-accel.redirect with a URI. NGINX will match this URI against its locations as if it was a normal request. It will then serve the location that matches the defined root + URI passed in the header.

Images (static files) requested through nginx/apache are fully logged with its size only in nginx logs. And apache logs size of only tech headers (approximately 300 bytes), which usually looks similar to the following:

    HTTP/1.1 200 OK
    Date: Tue, 10 Jan 2012 02:59:02 GMT
    Server: Apache/2.2.21 (FreeBSD)
    X-Accel-Version: 0.01
    X-Accel-Redirect: /int/some/static/file.txt
    Content-Length: 0
    Content-Type: text/plain

As a quick solution run this:

perl -pi -e 's|/var/log/httpd/domains/|/var/log/nginx/domains/|' /home/*/domains/*/awstats/.data/awstat*.conf

to make awstats to read nginx logs instead of apache. This changes will affect only existing domains. Newly created domains will still have awstat reading apache logs.

Run this:

perl -pi -e 's|/var/log/nginx/domains/|/var/log/httpd/domains/|' /home/*/domains/*/awstats/.data/awstat*.conf

to roll back and make awstats to read apache logs instead of nginx. This changes will affect only existing domains.

Related links:

About Us
We are a team of professionals, and specialize in installation, configuring and managing of remote virtual and dedicated servers powered by Linux/Unix-like OS with DirectAdmin. We support various sets of software, including web-servers Apache, Nginx; internet domain name servers Bind, PowerDNS; mail-servers with POP3, IMAP and SMTP, FTP-servers, etc. After years of working through the most complex server challenges our team has gathered valuable experience and universal solutions suitable for everyday tasks. We are here to lend you a helping hand and take care of your servers in order to let you have enough time to do more of what you love.

All of the information and data on this site is for informational purposes only and is provided for the convenience of the user.
Powered by: Amiro.CMS - Free edition