Forum Moderators: phranque

Message Too Old, No Replies

changing ports with a rewrite

geronimo running on 8080, I want my requests to be clean and simple

         

broniusm

11:42 pm on Mar 22, 2006 (gmt 0)

10+ Year Member



I have geronimo on 8080 and xwiki atop that. I would like my urls to come in like:
[wiki.srv...]
and end up serving up:
[srv:8080...]
If no document is specified (like "http://wiki.srv/"), it should go to ".../Main/" as above.
If a document <i>is</i> specified, however, it should replace Main as in:
[wiki.srv...] => [srv:8080...]

I have tried many incorrect permutations of rewrite, but for now, I'm having to just have a redirect of [wiki.srv...] => [srv:8080...] and that's all you get... Beside the basic annoyance of Always landing at /Main/, I also have the undesirable side-effect of [wiki.srv...] in URL-history sinking to the end of the list, After all the proper, subsequent :8080 requests which happened at a previous session.

Ideas? Note: these fictitious urls represent my intranet environment.

lammert

2:42 am on Mar 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It is not possible to change port numbers in a rewrite other than with an external 30x redirect, but you can use Apache as a reverse proxy server which catches the request from port 80 and redirects it to localhost:8080 for some parts of your site, but not all. This proxying happens on the server, and the visitor thinks that all content is accesible via port 80. The proxy call to port 8080 is completely transparent.

Setting up such a proxy server with mod_proxy requires some attention, because a small configuration error will turn your computer in an open proxy funerable for all types of malicious actions.

The code would look something like:

# This line is necessary, otherwise it is an open proxy
ProxyRequests Off

# Set some access rules, these will be good I think
<Proxy *>
Order deny,allow
Allow from all
</Proxy>

# Set up the reverse proxy
# See Apache manual for more details on these directives
# All requests for other directories than /ITDocs will
# be handled by the default HTTP server.
ProxyPass /ITDocs h**p://localhost:8080/xwiki/bin/view/ITDocs
ProxyPassReverse /ITDocs h**p://localhost:8080/xwiki/bin/view/ITDocs

broniusm

3:12 am on Mar 23, 2006 (gmt 0)

10+ Year Member



Interesting-- I had seen some mention of proxy within the rewrite module, but nothing seemed applicable. I will have to study up on proxy.

Because this is a wiki, it's not possible to write out every possible "directory" (ITDocs in this example). I imagine, however, that I may be able to proxy some "subdirectory" keyword, say, "wiki" as in h**p://srv/wiki/ITDocs, where /wiki would trigger the proxy, and rewrite on *:8080 could determine what to do with h**p://srv:8080/wiki/ITDocs. If so, how might I, now on the *:8080 config, handle "if nothing then Main, else \1"?

hmm.. that is, if I can even fiddle with a *:8080 since geronimo is sitting there controlling everything. I appreciate your help-- this is fun.

jdMorgan

3:31 pm on Mar 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Im not sure I understand your desired port-handling behaviour, but something like:

# If already on port 8080, skip next two rules
RewriteCond %{SERVER_PORT} ^8080$
RewriteRule ^/ - [S=2]
# Proxy root index requests to /xwiki/bin/view/Main on port 8080
RewriteRule ^/$ http://example.com:8080/xwiki/bin/view/Main/ [P,L]
# Proxy specific page requests to /xwiki/bin/view/<page> on port 8080
RewriteRule ^/(.+)$ http://example.com:8080/xwiki/bin/view/$1 [P,L]

Jim

broniusm

5:04 pm on Mar 31, 2006 (gmt 0)

10+ Year Member



jdMorgan: My apologies for a delayed response-- my reply notification seems to have a hiccup in it. I am very appreciative of and interested in your advice.

Your sample rewrite directives looks great: if we're on 8080 (which I'll never be at that point: this is in a vhosts.d config file for a given subdomain, for *:80), don't do the cool stuff. Otherwise, proceed and look for a request without a path and/or querystring, pass it to another place (the geronimo server on the same box in my case) on port:8080 via proxy (P). If there is something following (a specific wiki document request), pass it to the same server, port 8080 and include that document requested....

but it won't work for me.. I did notice that I didn't have mod_proxy running, but it is now (without any config..?), and still no va.

This vhosts.d file is for a particular subdomain on port 80, whereas (as in my sample urls above) geronimo is on the main domain, port 8080. Don't know if that will make a difference.