Welcome! Log In Create A New Profile

Advanced

Re: conditional auth_basic

Cedric Jeanneret
October 05, 2010 08:04AM
Ok, thank you for your answer.

A bit ugly, knowing we can put some conditions in nginx config file ;).

But this way is working.

Cheers,

C.

On Tue, 5 Oct 2010 15:40:30 +0400
Maxim Dounin <mdounin@mdounin.ru> wrote:

> Hello!
>
> On Tue, Oct 05, 2010 at 07:33:40AM +0200, Cedric Jeanneret wrote:
>
> > Hello,
> >
> > I have a special setup involving a wildcard :
> > server {
> > server_name *.domain.ltd
> > access_log /var/log/nginx/itnux_acces.log main;
> > error_log /var/log/nginx/itnux_error.log info;
> > add_header X-Devel "$host - production site";
> >
> >
> > location / {
> > proxy_pass http://localhost:9095;
> > proxy_set_header Host $host;
> > }
> > }
> >
> >
> > I'd like to add some auth_basic, only if $host is NOT "demo.domain.ltd".
> >
> > I thought I could make it like that:
> > location / {
> > proxy_pass http://localhost:9095;
> > proxy_set_header Host $host;
> > if ($host != 'demo.domain.ltd') {
> > auth_basic "Not for everyone ;)";
> > auth_basic_user_file /var/www/vhosts/domain.ltd/htaccess;
> > }
> > }
> >
> > But it seems that nginx doesn't like it:
> > nginx -t
> > [emerg]: "auth_basic" directive is not allowed here in /etc/nginx/vhosts/wildcard.domain.ltd.conf:17
> > configuration file /etc/nginx/nginx.conf test failed
> >
> > How can I do this ? Do I have to declare "demo.domain.ltd", and then the wildcard in two distinct servers ?
>
> Yes, use two distinct server{} blocks.
>
> server {
> server_name *.domain.ltd;
>
> auth_basic ...
>
> ...
> }
>
> server {
> server_name demo.domain.ltd;
>
> ...
> }
>
> Maxim Dounin
>
> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://nginx.org/mailman/listinfo/nginx


--
Cédric Jeanneret | System Administrator
021 619 10 32 | Camptocamp SA
cedric.jeanneret@camptocamp.com | PSE-A / EPFL
_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

conditional auth_basic

Cedric Jeanneret October 05, 2010 01:38AM

Re: conditional auth_basic

Maxim Dounin October 05, 2010 07:44AM

Re: conditional auth_basic

Cedric Jeanneret October 05, 2010 08:04AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 158
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready