Want to subscribe to topics you're interested in?
Become a Member

Can't protect a folder using python script

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

  1. pamamolf

    pamamolf Well-Known Member

    2,821
    253
    83
    May 31, 2014
    Ratings:
    +447
    Local Time:
    7:28 AM
    Nginx-1.13.x
    MariaDB 10.1.x
    Hi
    I am trying to protect a folder: /home/nginx/domains/mydomain.com/public/folderx/

    I just run:
    python /usr/local/nginx/conf/htpasswd.py -c -b /usr/local/nginx/conf/htpasswd admin passwordx

    Then i edit the vhost file of my domain: /usr/local/nginx/conf/conf.d/mydomain.com.conf
    and i try to add this inside:

    auth_basic "Private";
    auth_basic_user_file /usr/local/nginx/conf/htpasswd;

    This protect my site and not the folder...

    It seems that this is normal as i add it on:

    location / {

    So i create another location under the } of the above code like:

    location /home/nginx/domains/mydomain.com/public/folderx/ {
    auth_basic "Private";
    auth_basic_user_file /usr/local/nginx/conf/htpasswd;
    }

    save and restart but doesn't work again :(
    What i am doing wrong?
    On both cases i was restart nginx and then test.

    I got the info from here:
    Nginx and vBulletin Connect 5 Vhost

    Thanks
     
  2. eva2000

    eva2000 Administrator Staff Member

    30,956
    6,917
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,418
    Local Time:
    3:28 PM
    Nginx 1.13.x
    MariaDB 5.5
    location context match is web root relative so not

    location /home/nginx/domains/mydomain.com/public/folderx/

    but

    location /folderx/
     
  3. pamamolf

    pamamolf Well-Known Member

    2,821
    253
    83
    May 31, 2014
    Ratings:
    +447
    Local Time:
    7:28 AM
    Nginx-1.13.x
    MariaDB 10.1.x
    Ok i add this:

    location /folderx/ {
    auth_basic "Private";
    auth_basic_user_file /usr/local/nginx/conf/htpasswd;
    }

    Then i restart the nginx and again i can open the file.php inside the folderx :(
    I tested on another browser also...
     
  4. eva2000

    eva2000 Administrator Staff Member

    30,956
    6,917
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,418
    Local Time:
    3:28 PM
    Nginx 1.13.x
    MariaDB 5.5
    Code:
    location ^~/folderx/ {
    auth_basic "Private";
    auth_basic_user_file /usr/local/nginx/conf/htpasswd;
    }
    manual Module ngx_http_core_module

     
    • Like Like x 1
  5. pamamolf

    pamamolf Well-Known Member

    2,821
    253
    83
    May 31, 2014
    Ratings:
    +447
    Local Time:
    7:28 AM
    Nginx-1.13.x
    MariaDB 10.1.x
    Working :)