Location problems

Igor Clark igor at pokelondon.com
Thu Feb 28 22:41:34 MSK 2008


On 19 Feb 2008, at 11:23, Denis F. Latypoff wrote:
>

> -          location ~ /admin/.* {
> +          location /admin { # not tested

Thanks Denis, and sorry for the delay in replying.

Unfortunately that didn't work, and I'm still having the same sort of  
problems with the location directive.

On another PHP site, I'm trying to restrict access to /admin via IP.
I have the following config, which works fine, though perhaps not  
optimal:

>     server {
>         listen      80;
>         server_name	server.name;
>
>         access_log	/path/to/logs/access.log	main;
>         error_log	/path/to//logs/error.log		info;
>
>         location / {
>             root		/path/to//public;
>             index		index.php index.html;
>
>             # if requesting /, rewrite to frontend.php and stop
>             rewrite	^/$	/frontend.php last;
>
>             # Set $control_path to $my_request_uri, in case there  
> are any
>             # custom rules above that might have changed it
>             # Then, rewrite using the last rules
>             if (!-e $request_filename) {
>                 rewrite	^/admin/(.*)$							/admin.php?CONTROL_PATH= 
> $1 last;
>                 rewrite	^/speakers/(.+)/?$					/speakers/video/$1;
>                 rewrite	^/financethemes/(.+)/?$				/financethemes/ 
> video/$1;
>                 rewrite	^/transcripts/(speaker|theme)/(.+)/?$	/ 
> transcripts/view/$1/$2;
>                 rewrite	^(.*)$								/frontend.php?CONTROL_PATH=$1  
> last;
>             }
>
>             location ~ \.flv$ {
>                 flv;
>             }
>
>             location /admin {
>                 allow   82.108.140.18;
>                 deny    all;
>             }
>
>             # pass the PHP scripts to FastCGI server listening on  
> 127.0.0.1:9999
>             location ~ \.php$ {
>                 fastcgi_pass				127.0.0.1:9999;
>                 fastcgi_index			index.php;
>                 fastcgi_intercept_errors	on;
>                 include					conf/fastcgi_params;
>             }
>         }
>         error_page  404         /404.html;
>         error_page  500         /500.html;
>     }

I just want to do the following, but still have all the other  
directives work, so that rewrites and PHP work under /admin:

         location /admin {
             allow   1.2.3.4;
             deny    all;
         }

How should I go about this? Where should I put the /admin location  
block? Nothing I do seems to work. I understand that the first matched  
regular expression stops the search, but as I can't seem to get  
nesting locations to work, what should I do?

(By the way, this is the first time we've used the FLV module, and  
we're really pleased with the results, so thanks!)

Best wishes
Igor

On 19 Feb 2008, at 11:23, Denis F. Latypoff wrote:

> Hello Igor,
>
> Tuesday, February 19, 2008, 5:04:48 PM, you wrote:
>
>> Hi folks,
>
>> I often have problems trying to use different locations without  
>> having
>> to duplicate config.
>> I think I must be thinking about it the wrong way!
>
>> Basically I just want to make /admin/ password-protected, but inherit
>> all the other config.
>
>> So I tried this:
>
>>        location / {
>>                include /path/to/php.conf;      # includes all  
>> fastcgi stuff and some
>> rewrites
>>                location ~ /admin/.* {
>>                        auth_basic              "Restricted";
>>                        auth_basic_user_file    /path/to/ 
>> admin.htusers;
>>                }
>>         }
>
>> But it doesn't work, so I tried this way which I've made work before:
>
>>        location / {
>>                include /path/to/php.conf;
>>         }
>
> -          location ~ /admin/.* {
> +          location /admin { # not tested
>>                auth_basic              "Restricted";
>>                auth_basic_user_file    /path/to/admin.htusers;
>>                include /path/to/php.conf;
>>        }
>
>> But this doesn't work either, it includes the PHP file but doesn't do
>> the auth, and there's no error in the log. I've tried various
>> permutations on ~ /admin/.* too.
>
>> What am I doing wrong?
>
>> Many thanks,
>> Igor
>
>> --
>> Igor Clark // POKE // 10 Redchurch Street // E2 7DD // +44 (0)20 7749
>> 5355 // www.pokelondon.com
>
>
>
> -- 
> Best regards,
> Denis                            mailto:denis at gostats.ru
>
>

--
Igor Clark // POKE // 10 Redchurch Street // E2 7DD // +44 (0)20 7749  
5355 // www.pokelondon.com




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nginx.org/pipermail/nginx/attachments/20080228/cb8c2ff7/attachment.html>


More information about the nginx mailing list