2012-02-14 16 views
16

Come posso abilitare l'autenticazione di base HTTP per tutto eccetto per un determinato file?nginx: auth_basic per tutto tranne una posizione specifica

Qui è la mia configurazione del blocco corrente del server per la posizione:

location/{ 
     auth_basic "The password, you must enter."; 
     auth_basic_user_file /etc/nginx/htpasswd; 
} 

location /README { 
     auth_basic off; 
} 

Tuttavia, /README, è ancora spingendo per una password.

Come possiamo risolvere questo problema?

Grazie! Mark

risposta

33

tenta di utilizzare il segno =, che ti aiuta:

location = /README { 
     auth_basic off; 
     allow all; # Allow all to see content 
} 
+4

è 'consentire a tutti 'veramente necessario? Non è un comportamento predefinito? – Joost

+0

Non è necessario. – KittMedia

+0

Downvoted - spiega perché è necessaria una corrispondenza completa qui. – Xaser

7

sto facendo qualcosa di simile utilizzando "mappa" invece di "se" per assegnare la variabile regno e htpasswd auth_basic di file:

map $http_host $siteenv { 
    default  dev; 

    ~^(?<subdomain>.+)\.dev dev; 
    ~^(?<subdomain>.+)\.devprofile devprofile; 
    ~^(?<subdomain>.+)\.devdebug devdebug; 
    ~^(?<subdomain>.+)\.test test; 
    ~^(?<subdomain>.+)\.demo demo; 
    ~^(?<subdomain>.+)\.stage stage; 

    # Live 
    ~^(?<subdomain>.+)\.live live; 
    ~^.*\.(?P<subdomain>.+)\.[a-zA-Z]* live; 
} 

map $http_host $auth_type { 
    default  "Restricted"; 

    ~^(?<subdomain>.+)\.dev "Development"; 
    ~^(?<subdomain>.+)\.devprofile "Development"; 
    ~^(?<subdomain>.+)\.devdebug "Development"; 
    ~^(?<subdomain>.+)\.test "Testing"; 
    ~^(?<subdomain>.+)\.stage "Stage"; 
    ~^(?<subdomain>.+)\.demo "Demo"; 

    # Live 
    ~^(?<subdomain>.+)\.live "off"; 
    ~^.*\.(?P<subdomain>.+)\.[a-zA-Z]* "off"; 
} 

server { 
    .. etc .. 

    auth_basic   $auth_type; 
    auth_basic_user_file /etc/nginx/conf.d/htpasswd-$siteenv; 
} 
Problemi correlati