Htpasswd for Opencart directory and Nginx only (Solved)

Hi! I want to protect the admin panel login for cms opencart (located in /admin/).
I created .htpasswd in the /admin/ directory and made these settings for the template:

    location /admin/ {
    try_files $uri $uri/ =404;
    auth_basic "Password-protected Area";
    auth_basic_user_file %docroot%/admin/.htpasswd;

But when I go to the domain/admin link and log in, I just download the file config.php and I can’t log in to the opencart admin panel. I only use nginx without apache. What did I do wrong?)

%docroot% doesnt work in .htaccess, you need to write that one out.

Should be replaced by /home/user/web/domain/public.html

I saw similar settings for Apache on the forum, but I only use Nginx and specifically noted this. I tried to specify the full path, the result was the same.

The working solution is:

location ^~ /admin {
    location ~ .(php)$ {
        try_files $uri =404;
        fastcgi_pass %backend_lsnr%;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $request_filename;

   auth_basic "Password-protected Area";
   auth_basic_user_file %docroot%/admin/.htpasswd;
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.