Learn about Centmin Mod LEMP Stack today
Become a Member

Nginx Protected folder is downloading the file and not open it on browser

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by pamamolf, Dec 2, 2014.

  1. pamamolf

    pamamolf Well-Known Member

    2,820
    253
    83
    May 31, 2014
    Ratings:
    +447
    Local Time:
    6:33 AM
    Nginx-1.13.x
    MariaDB 10.1.x
    Hi

    I try to password protect a folder using:

    Code:
    python /usr/local/nginx/conf/htpasswd.py -c -b /usr/local/nginx/conf/htpasswdnew usernamehere passwordhere
    and then add the code to domain config file: mydomain.com.conf under the:

    Code:
      # Enable for vBulletin usage WITHOUT vbSEO installed
       try_files        $uri $uri/ /index.php;
    
      }
    like:

    Code:
    location ^~/admin/ {
    auth_basic "Private";
    auth_basic_user_file /usr/local/nginx/conf/htpasswdnew;
    }

    And then i restart nginx and go to path and add the user and pass and then when is accepted it just download the php file and not open it on browser :(
     
  2. eva2000

    eva2000 Administrator Staff Member

    30,947
    6,915
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,413
    Local Time:
    2:33 PM
    Nginx 1.13.x
    MariaDB 5.5
    you'd need to include the php.conf include file within the protection location context

    Code:
    location ^~/admin/ {
    auth_basic "Private";
    auth_basic_user_file /usr/local/nginx/conf/htpasswdnew;
    include /usr/local/nginx/conf/php.conf;
    }
     
    • Like Like x 1
  3. pamamolf

    pamamolf Well-Known Member

    2,820
    253
    83
    May 31, 2014
    Ratings:
    +447
    Local Time:
    6:33 AM
    Nginx-1.13.x
    MariaDB 10.1.x
    Great thanks !!!! :)