Subdirectory still redirecting to www. despite rule

This issue is connected to the threads

rewrite to www EXCEPT for one directory
(http://www.ruby-forum.com/topic/4405551) and

Nginx location rule for Wordpress Multisite in subdirectories
(http://www.ruby-forum.com/topic/4405180)

After making the changes to my nginx.conf. I reloaded the config. After
going to example.com/blogs/wp-admin/install.php the browser still
redirected to www.example.com/blogs/wp-admin/install.php

Here are the applicable lines in the conf:

server {
server_name example.com;
listen 80;

location / {
return 301 http://www.example.com$request_uri;
}

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/$blogname {
try_files $uri $blogname/index.php?q=$uri;
location ~ .php$ {
fastcgi_pass 127.0.0.1:10004;
}
}
}

I’m wondering if it’s an error in combining the config advice for the
two
separate issues in the two threads.

Thanks.

Stop using a browser to test with and instead do curl -I
Browsers cache, always.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,230832,230833#msg-230833

On Tue, September 18, 2012 8:36 pm, Ensiferous wrote:

Stop using a browser to test with and instead do curl -I
Browsers cache, always.

a) I had never been to the URL before and b) I had cleared the browser’s
cache before testing.

running curl -I I get:

HTTP/1.1 200 OK
Server: nginx/1.2.2
Date: Wed, 19 Sep 2012 00:53:36 GMT
Content-Type: text/html
Connection: keep-alive

In Firefox with cache cleared, I get the redirect to the WP install page
on www.example.com instead of staying at example.com

On 19/09/2012 3:21 AM, Valentin V. Bartenev wrote:

}
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

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/([^/]+) {
     ...
  }

}

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.

wbr, Valentin V. Bartenev

On 19 Set 2012 10h01 CEST, [email protected] wrote:

On 19/09/2012 3:21 AM, Valentin V. Bartenev wrote:

}

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

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
[email protected]
http://mailman.nginx.org/mailman/listinfo/nginx

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs