Rewrite to localhost:8000
Posted:
09. December 2013 16:21
by mcv
I've got XAMPP running on port 80, and a web app on port 8000. I need a rewrite rule so that requests coming in on port 80 are sent to the web app on port 8000, without the browser noticing.
It seems like a fairly simple and obvious thing to do, but I simply cannot figure it out. Usually I get some kind of error message (400 Bad Request, 500 Server Error). The best attempt gave a browser redirect, which isn't what I need, but I figured adding a [P] or maybe [PT] flag would do it, but that resulted in an error.
So what's the correct way to do this?
Re: Rewrite to localhost:8000
Posted:
10. December 2013 12:15
by Nobbie
What you need to configure is a so called "Reverse Proxy". You cannot solve your problem with a Rewrite, as you redirect to a different server and this is evaluated by the browser.
Re: Rewrite to localhost:8000
Posted:
10. December 2013 13:39
by mcv
But I don't want it evaluated by the browser. I want the browser to talk just to Apache, and Apache to hand the request to my app.
I guess I'm going to need something like:
- Code: Select all
ProxyPass ^(.*) http://localhost:8000{REQUEST_URI}
ProxyPassReverse ^{.*}http://localhost:8000{REQUEST_URI}
Or maybe just
- Code: Select all
ProxyPass /app(.*) http://localhost:8000/app$1
ProxyPassReverse /app(.*) http://localhost:8000/app$1
Although the mod_proxy page sounds like [P] should also work:
A reverse proxy is activated using the ProxyPass directive or the [P] flag to the RewriteRule directive.
Re: Rewrite to localhost:8000
Posted:
10. December 2013 13:50
by Nobbie
mcv wrote:I guess I'm going to need something like:
- Code: Select all
ProxyPass ^(.*) http://localhost:8000{REQUEST_URI}
ProxyPassReverse ^{.*}http://localhost:8000{REQUEST_URI}
As i wrote above. But this is an ugly ProxyPass.
mcv wrote:A reverse proxy is activated using the ProxyPass directive or the [P] flag to the RewriteRule directive.
Yes, but you dont need a rewrite, you need a ReverseProxy Only. The easies and best way of creating a working ProxyPass is a VirtualHost with a ProxyPass (so you can pass all Requests to the ReverseProxy). Create any Subdomainname and create a VirtualHost:
- Code: Select all
<VirtualHost *:80>
Servername OtherApp
ProxyPass / http://localhost:8000/
ProxyPassReverse / http://localhost:8000/
</VirtualHost>
And if you enter
http://OtherApp into your Browser, it will show the contents of localhost:8000
Re: Rewrite to localhost:8000
Posted:
10. December 2013 15:05
by mcv
Nobbie wrote:- Code: Select all
<VirtualHost *:80>
Servername OtherApp
ProxyPass / http://localhost:8000/
ProxyPassReverse / http://localhost:8000/
</VirtualHost>
And if you enter http://OtherApp into your Browser, it will show the contents of localhost:8000
Thanks! That looks exactly like what I need.