Using auth_basic in dynamic vhosts

Manlio Perillo manlio_perillo at libero.it
Mon Jul 7 19:38:13 MSD 2008


Lee Brotherston ha scritto:
> Hi,
> 
> I have an nginx installation which allows vhosts to be setup
> dynamically:
> 
> -------8<-------
> 
> server {
>         listen          10.1.2.3:80;
>         root            /data/www/$host;
>         index           index.php index.html;
> 
>         location ~ .php$ {
>                 include         fastcgi_params;
>                 fastcgi_pass    unix:/tmp/.fastcgi.www/socket;
>                 fastcgi_index   index.php;
>                 fastcgi_param   SCRIPT_FILENAME /data/www/$host/$fastcgi_script_name;
>                 fastcgi_param   DOCUMENT_ROOT   /data/www/$host/;
>         }
> 
> -------8<-------
> 
> I had trouble writing a way to block access to certain directories,
> without applying them to all vhosts.  However I eventually realised
> that you could do this:
> 
> -------8<-------
>         if ($host ~* specific-vhost.domain.com) {
>                 rewrite ^/private.* @403;
>                 rewrite ^/admin.* @403;
>         }
> 
>         location = @403 {
>                 return 403;
>         }
> 
> -------8<-------
> 

Isn't it better to simply add complete server blocks for these specific 
hosts?

 > [...]


Manlio Perillo





More information about the nginx mailing list