Subdirectory still redirecting to www. despite rule

António P. P. Almeida appa at perusio.net
Wed Sep 19 09:02:00 UTC 2012


On 19 Set 2012 10h01 CEST, ianevans at digitalhit.com wrote:

On 19/09/2012 3:21 AM, Valentin V. Bartenev wrote:
> On Wednesday 19 September 2012 04:25:53 Ian M. Evans wrote:
> [...]
>> location ^~ /blogs {
>>    try_files $uri /blogs/index.php?q=$uri;
>>    location ~ \.php$ {
>>    fastcgi_pass 127.0.0.1:10004;
>> }
>> }
>> if ($uri ~ (/blogs/[^/]*)) {
>>    set $blogname $1;
>> }
>
>    location /blogs {
>
>        ...
>
>        location ~ ^/blogs/([^/]+) {
>           ...
>        }
>    }

The suggested config of adding a variable is over complicated and very
little Nginxy. That's seems like a throwback to Apache's style IMO.

Valentin's suggestion with blogname being a capture in a regex based
(nested) location is a much cleaner way. It's also informative in the
way Nginx configuration language works. It's mostly declarative.

Try it out.

--- appa


> But your example config is completely broken. Probably you do not understand how
> "location" works. If so, you should read these articles:
>
>   http://nginx.org/en/docs/http/request_processing.html
>   http://nginx.org/r/location
>
>
>> location ^~ /blogs/$blogname {
>
> Variables are not allowed here.
>

As it turns out, the issue was a missing document root (since I 
previously only used that server section to redirect to www) Added the 
root and it worked fine.

As for the variable in the location, I did not write that. It was 
suggested to me in the thread:

http://www.ruby-forum.com/topic/4405180#1073498

_______________________________________________
nginx mailing list
nginx at nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx



More information about the nginx mailing list