Remove URI string?

Hello all -

I would like to strip all request_uri strings for a group of server
names
and serve up an index page.
Example:

Client requests http://host1.domain.com/blah, nginx will direct client
to
http://host1.domain.com and serve the index page. Same scenario for
host2 -
I would like nginx to direct client to http://host2.domain.com and serve
the
same index page.

Would the below work?

server {
server_name host1.domain.com host2.domain.com;
rewrite ^ http://$server_name;
root /path/to/document/root;
index index.html;
}

Thank you!

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

On 9 January 2013 16:35, daveyfx [email protected] wrote:

Would the below work?

server {
server_name host1.domain.com host2.domain.com;
rewrite ^ http://$server_name;
root /path/to/document/root;
index index.html;
}

Have you tried it? How about doing that?

It looks ok to me, but running it on a test machine will probably tell
you all you need to know …

Jonathan

Jonathan M. // Oxford, London, UK
http://www.jpluscplusm.com/contact.html

I gave it a try and it did not work out. My access log repeated the
following entry ~ 20 times.

[09/Jan/2013:23:31:47 -0500] “GET / HTTP/1.1” 302 160 “-” “Mozilla/5.0
(Windows NT 6.1; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0”

Firefox kindly informed me that “The page isn’t redirecting properly”
I’m
guessing it’s getting caught in an infinite redirect.

Is there anything else I can try?

Thank you!

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

On Thu, Jan 10, 2013 at 11:35 AM, daveyfx [email protected] wrote:

location = / {
index index.html;
}
location / {
return 302 /;
}

On Thu, Jan 10, 2013 at 9:29 PM, daveyfx [email protected] wrote:

location / {
return 302 /;
}

Thank you for the suggestion Edho. Unfortunately this still gave me a
redirect loop.

clear your browser’s history. Actually, don’t use browser for testing
redirect. Use curl.

And make sure you’ve removed all other rewrites.

Edho A. Wrote:

properly" I’m
}

Thank you for the suggestion Edho. Unfortunately this still gave me a
redirect loop.


nginx mailing list
[email protected]
http://mailman.nginx.org/mailman/listinfo/nginx

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

On Thu, Jan 10, 2013 at 11:37:44AM +0700, Edho A. wrote:

On Thu, Jan 10, 2013 at 11:35 AM, daveyfx [email protected] wrote:

Hi there,

I gave it a try and it did not work out. My access log repeated the
following entry ~ 20 times.

As mentioned:

curl -i http://server/something
curl -i http://server/

are much friendlier for testing with. You’ll see exactly what the server
sends back.

location = / {
index index.html;
}
location / {
return 302 /;
}

With that configuration, a request for / will lead to an internal
rewrite to /index.html, which will then hit the second location and do
an external redirect again.

So either add a third “location = /index.html” to handle that, or avoid
the internal rewrite by doing something like

try_files /index.html =404

in the “location = /” block.

f

Francis D. [email protected]

Francis D. Wrote:

As mentioned:

}
the internal rewrite by doing something like

try_files /index.html =404

in the “location = /” block.

f

To all -

Thank you for your help with this. Francis put the puzzle together and
the
following is working out great for me.

server {
server_name
host1.domain.com
host2.domain.com

… (so on and so forth)

root /path/to/document/root;

location = / {
    try_files /index.html = 404;
}

location / {
    return 302 /;
}

}


Francis D. [email protected]

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

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