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 2013-01-09 17:36
on 2013-01-09 17:44
On 9 January 2013 16:35, daveyfx <nginx-forum@nginx.us> 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 Matthews // Oxford, London, UK http://www.jpluscplusm.com/contact.html
on 2013-01-10 05:36
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 2013-01-10 05:38
On Thu, Jan 10, 2013 at 11:35 AM, daveyfx <nginx-forum@nginx.us> wrote:
>
location = / {
index index.html;
}
location / {
return 302 /;
}
on 2013-01-10 15:29
Edho Arief Wrote: ------------------------------------------------------- > properly" I'm > } > Thank you for the suggestion Edho. Unfortunately this still gave me a redirect loop. > _______________________________________________ > nginx mailing list > nginx@nginx.org > http://mailman.nginx.org/mailman/listinfo/nginx Posted at Nginx Forum: http://forum.nginx.org/read.php?2,234822,234906#msg-234906
on 2013-01-10 15:43
On Thu, Jan 10, 2013 at 9:29 PM, daveyfx <nginx-forum@nginx.us> 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.
on 2013-01-10 17:13
On Thu, Jan 10, 2013 at 11:37:44AM +0700, Edho Arief wrote: > On Thu, Jan 10, 2013 at 11:35 AM, daveyfx <nginx-forum@nginx.us> 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 Daly francis@daoine.org
on 2013-01-11 00:26
Francis Daly 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 Daly francis@daoine.org Posted at Nginx Forum: http://forum.nginx.org/read.php?2,234822,234914#msg-234914
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.