Welcome! Log In Create A New Profile

Advanced

Re: auth_basic error nginx: [emerg] "auth_basic" directive is not allowed here in

Maxim Dounin
October 15, 2014 09:48AM
Hello!

On Wed, Oct 15, 2014 at 08:51:43AM -0400, shambler81 wrote:

> правильно ли я поимю чо нуно что-то вроде ?
>
> set $true1
> if ($http_host ~* "^(dev|www.dev)\..*\..{2,8}$"){
> auth_basic "Unauthorized";
> }
> set $true2
> if ($http_host ~* "^(dev|www.dev)\..*\..{2,8}$"){
> auth_basic_user_file /var/www/dev_htpasswd;
> }
>
> .....
> location / {
> ...
> $true1
> $true1

Нет.

Во-первых, как уже было сказано, в данном случае - правильным
решением будет сделать два отдельных блока server{}:

server {
server_name example.com;

# public site, no auth_basic here

...
}

server {
server_name dev.example.com www.dev.example.com;

auth_basic "Closed site";
auth_basic_user_file /path/to/htpasswd;

...
}

Во-вторых, переменные можно использовать в качестве параметра
директивы, а не вместо неё в конфиге. Т.е. в общем случае можно
требовать или не требовать аутентификацию как-то так:


set $realm "Closed site";

if (...auth required...) {
set $realm "off";
}

auth_basic $realm;
auth_basic_user_file /path/to/htpasswd;

--
Maxim Dounin
http://nginx.org/

_______________________________________________
nginx-ru mailing list
nginx-ru@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-ru
Subject Author Posted

auth_basic error nginx: [emerg] "auth_basic" directive is not allowed here in

shambler81 October 15, 2014 07:55AM

Re: auth_basic error nginx: [emerg] "auth_basic" directive is not allowed here in

Maxim Dounin October 15, 2014 08:10AM

Re: auth_basic error nginx: [emerg] "auth_basic" directive is not allowed here in

shambler81 October 15, 2014 08:51AM

Re: auth_basic error nginx: [emerg] "auth_basic" directive is not allowed here in

Maxim Dounin October 15, 2014 09:48AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 163
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready