Discover Centmin Mod today
Register Now

Can't protect a folder using python script

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

  1. pamamolf

    pamamolf Premium Member Premium Member

    4,101
    428
    83
    May 31, 2014
    Ratings:
    +837
    Local Time:
    6:26 PM
    Nginx-1.26.x
    MariaDB 10.6.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

    55,234
    12,253
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,831
    Local Time:
    1:26 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    location context match is web root relative so not

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

    but

    location /folderx/
     
  3. pamamolf

    pamamolf Premium Member Premium Member

    4,101
    428
    83
    May 31, 2014
    Ratings:
    +837
    Local Time:
    6:26 PM
    Nginx-1.26.x
    MariaDB 10.6.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

    55,234
    12,253
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,831
    Local Time:
    1:26 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Code:
    location ^~/folderx/ {
    auth_basic "Private";
    auth_basic_user_file /usr/local/nginx/conf/htpasswd;
    }
    manual Module ngx_http_core_module

     
  5. pamamolf

    pamamolf Premium Member Premium Member

    4,101
    428
    83
    May 31, 2014
    Ratings:
    +837
    Local Time:
    6:26 PM
    Nginx-1.26.x
    MariaDB 10.6.x
    Working :)