Awstats auth not working on nginx+phpfpm setup

So, when i enable awstats on domain, hestia correctly populates:
“/home/USER/web/DOMAIN/stats” folder with data, and if i go to domain.tld/vstats/ i can see Awstats data.

Problem starts when i want to enable authorization.

When i enable authorization, few things happen:

  1. .htpasswd file is create in “/home/USER/web/DOMAIN/stats” folder. That file has my username and hashed password in it, as it should
  2. /home/USER/conf/web/DOMAIN.auth file is created. That file has two lines:
auth_basic "Web Statistics";
auth_basic_user_file /home/USER/web/DOMAIN/stats/.htpasswd;

It basically tells to nginx it should ask for user and pass stored in file from 1)
All fine for now.
3) /home/USER/conf/web/domain/awstats.conf is created with bunch of data in it
I don’t know what exactly that data is, but by the looks of it, it’s bunch of nginx related configuration vars. Should be fine.

But, with all that, i am not asked for authorization if i open stats of that domain.
I took a look into nginx.conf file of that domain, and “stats” location it has this:

location /vstats/ {
alias /home/USER/web/DOMAIN/stats/;
include /home/USER/web/DOMAIN/stats/auth.conf*;
}

As you can see, template thinks that there is “auth.conf*” file in stats folder when there is none.
My wild guess is that “auth.conf*” file is in fact “DOMAIN.auth” file that is created in step 2)

What i do not know is what is real error. Template searching for wrong file in wrong directory, or is DOMAIN.auth file created under wrong directory and under wrong name?

If i edit template so it loads DOMAIN.auth file, authorization works fine. So, i am wondering, what would be long term fix for this? Editing every php-fpm template so that it searches for DOMAIN.auth file, or should i search for file that creates that DOMAIN.auth file and somehow change it so that it creates it under “stats” directory and by name that all templates think it’s called?

My guess is that neather of those fixes will be permanent, and that it should be fixed by commmiting that change to git, but i do not know Hestia good enough so i don’t know which option would be fixing and which one would be reverting to some old state.

1 Like

The best way to fix the issue on you local server is to create a new template file with your changes.

How ever if all the current templates file are affected please create a issue report with all the detailed information / changes that need to be made or if you now how Git works please create a pull request. In that case we can review the changes and release it with the next update.

The default template files can be found in https://github.com/hestiacp/hestiacp/tree/main/install/deb/templates/web/nginx/php-fpm

or https://github.com/hestiacp/hestiacp/issues.

All the help is really appreciated how ever it can take some time before pull requests are accepted.

1 Like

Yes, i will fix it by creating custom template files. Changes are really small (only one line per template) and it will hold untill better solution is created (on that more below).

What i am struggleing with is more of “philosophical” issue of what is better way of fixing this error. By changing templates to point to : /home/USER/conf/web/DOMAIN.auth file OR would it be better to change code that creates that file and create file in “/home/USER/web/DOMAIN/stats” where template files expect it to be (and under different name).

First solution is easy for me, and i would even know how to publish it to git repo but it looks like wrong solution. For some reason, i have feeling that auth file should not be in place where it is right now, and that it really should be in “/home/USER/web/DOMAIN/stats” directory OR in “/home/USER/conf/web/DOMAIN” dir.

Problem with that second “better” (at least by me) solution is that i have no idea where is code that creates that file so i don’t know where to change it.

And maybe i’m totally wrong, maybe auth file should be where it is right now and only changing all templates is really better way.

Longer i think about it, more it bothers me and more i think that file should be moved to “/home/USER/conf/web/DOMAIN” folder, named as it is right now, AND all templates than should be changed to point to that file.
It’s kinda logical. “DOMAIN.auth” file is part of nginx configuration and it should be in “/home/USER/conf/web/DOMAIN” folder just like rest of .conf files are.

If you can point me in right direction on where to find code that creates that file, i would gladly change it AND edit all template files to find it by it’s name.

Ok i found where that file is created. It’s v-add-web-domain-stats-user script in bin folder and v-delete-web-domain-stats-user for time when auth is removed.

For a test i changed .auth file in a way that it’s created in “stats” folder and by name that templates expect it to be, and auth is working now as it should be.

Now what i really am not sure about is should that file be there, or should it be in conf dire with rest of nginx conf files…