Author |
|
giopas
Joined: 18 Nov 2015 Posts: 29
|
Posted: Tue 24 Nov '15 16:42 Post subject: Redirect Vhost (*:80) to another Vhost (*:88) |
|
|
Hi there again,
I have a peculiar question somehow related to this topic.
As I could not make my QNAP official Apache server (v 2.2.31) properly handling web socket connections (as this requires mod_proxy_wstunnel extention of mod_proxy for Apache > 2.4.5), I have installed a new, separate Apache server (v 2.4.12) running on port 88.
I know that this is not a good solution, but it is temporary (until QNAP does not upgrade its official server).
I have therefore created a new VirtualHost which does its job correctly and I can now use (from outside my corporate network) KeyBox:
Code: | <VirtualHost *:88>
ServerName sub.domain.com
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<LocationMatch "/admin/(terms.*)">
ProxyPass ajp://localhost:58000//admin/$1 <- not sure it is indeed necessary
ProxyPassReverse ajp://localhost:58000/admin/$1 <- not sure it is indeed necessary
ProxyPass ws://localhost:58000/admin/$1
ProxyPassReverse ws://localhost:58000/admin/$1
</LocationMatch>
ProxyPass / http://localhost:58000/
ProxyPassReverse / http://localhost:58000/
ProxyRequests Off
ProxyPreserveHost On
ProxyStatus On
</VirtualHost> |
My problem is that, as I cannot access from work to port 88 (like initial 58000) on my server, I would need a redirect such connection to port 80.
How can I do this? I could set another Reverse Proxy, but probably I would again be stuck with the initial web socket connection handling problem.
Otherwise I could create a simple index.php on a virtual host on port 80, but again I don't think it would work:
Code: | <?
header('Location: http://.'$_SERVER["SERVER_ADDR"]'.:'88');
> |
Any advice would be really appreciated.
giopas |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7373 Location: Germany, Next to Hamburg
|
Posted: Thu 26 Nov '15 18:40 Post subject: |
|
|
Why not the vhost on port 80? Why it is on 88? |
|
Back to top |
|
giopas
Joined: 18 Nov 2015 Posts: 29
|
Posted: Thu 26 Nov '15 18:55 Post subject: |
|
|
Because I have already the other apache (2.2.x) server running on port 80...
As you know, would it be possible to set port forwarding of my router in this way?
Quote: | Wan Port 80 <-> Local Port 80 of the IP of the apache 2.2.x server
Wan Port 80 <-> Local Port 88 of the IP of the apache 2.4.x server |
Would this work?
EDIT: otherwise, can I use Proxy Remote Directive to forward incoming requests to apache 2.2.x to the reverse proxy apache 2.4.x? Or use a forward proxy (if web socket connections are supported as forward proxy under apache 2.2.x)? |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7373 Location: Germany, Next to Hamburg
|
Posted: Thu 26 Nov '15 19:11 Post subject: |
|
|
Yes the portforwarding on your router would do the trick! WAN:80<--->LAN:88
And inside your network you can use the :88 in the url |
|
Back to top |
|
giopas
Joined: 18 Nov 2015 Posts: 29
|
Posted: Thu 26 Nov '15 19:16 Post subject: |
|
|
So the two apache servers would understand that in one case the request is for one and in the other... for the other? Nothing more to set other than the port forwarding? |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7373 Location: Germany, Next to Hamburg
|
Posted: Fri 27 Nov '15 0:29 Post subject: |
|
|
You just configure the portforwarding from incoming on port 80 to forward to port 88 on the device. No config change needed. The apache apache on port 80 won't get the request at all. Only your self installed apache on port 88. |
|
Back to top |
|
giopas
Joined: 18 Nov 2015 Posts: 29
|
Posted: Fri 27 Nov '15 8:58 Post subject: |
|
|
I tried but if on my router (an Asus rt-87u) I set port forwarding of port 80 both to port 80 (I still need it for other web services) and 88 (for the reverse proxy), the router tells me that this is not possible and it is right to say so.
Is there a way to make apache 2.2 (on port 80) to accept the request and forward it to apache 2.4 (on port 8 without let it to handle web sockets? |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7373 Location: Germany, Next to Hamburg
|
Posted: Sat 28 Nov '15 10:50 Post subject: |
|
|
Sure,
create a reverse proxy on the apache 2.2.
Code: | internet<--->router<--->2.2<--->2.4<--->58000 |
|
|
Back to top |
|
giopas
Joined: 18 Nov 2015 Posts: 29
|
Posted: Sat 28 Nov '15 11:11 Post subject: |
|
|
But if apache 2.2 does not handle web sockets (which is properly handled by 2.4) how to set it?
Moreover how should I put sub domains? Should I use the same or another?
Could you please help me on this?
EDIT: as stated above, currently I have the following config on apache 2.4
Code: | <VirtualHost *:88>
ServerName sub.domain.com
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<LocationMatch "/admin/(terms.*)">
ProxyPass ws://localhost:58000/admin/$1
ProxyPassReverse ws://localhost:58000/admin/$1
</LocationMatch>
ProxyPass / http://localhost:58000/
ProxyPassReverse / http://localhost:58000/
ProxyRequests Off
ProxyPreserveHost On
ProxyStatus On
</VirtualHost> |
and this is the (exactly the same, only port changes) on apache 2.2. (knowing that because of the server version it actually does not work properly):
Code: | <VirtualHost *:80>
ServerName sub.domain.com
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<LocationMatch "/admin/(terms.*)">
ProxyPass ws://localhost:58000/admin/$1
ProxyPassReverse ws://localhost:58000/admin/$1
</LocationMatch>
ProxyPass / http://localhost:58000/
ProxyPassReverse / http://localhost:58000/
ProxyRequests Off
ProxyPreserveHost On
ProxyStatus On
</VirtualHost> |
Should I create another reverse proxy on apache 2.2 to connect to this one or can I just use a mod_rewrite on a virtual host on apache 2.2 so that every request to sub.domain.com:80 is actually sent and handled to the virtual host on port 88? Would this work?
How to do that? |
|
Back to top |
|
giopas
Joined: 18 Nov 2015 Posts: 29
|
Posted: Tue 01 Dec '15 0:34 Post subject: |
|
|
You think there is nothing to do to solve this issue? I'm out of ideas.. |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7373 Location: Germany, Next to Hamburg
|
Posted: Tue 01 Dec '15 15:07 Post subject: |
|
|
I thought my sketch was enough.
The reverse proxy on 2.4:88 is ok ( if it is working from inside the LAN).
Configure a different reverse proxy on the 2.2:80 apache with a simple http reverse proxy to the 2.4:88 sub.domain.com:88
Code: |
internet<--http-->router<--portforward-->2.2:80<--http-->2.4:88<--ws-->server:58000
|
I hope that make it clear. If not some other may help. |
|
Back to top |
|
giopas
Joined: 18 Nov 2015 Posts: 29
|
Posted: Tue 01 Dec '15 16:23 Post subject: |
|
|
Hi JB, thank you for your support.
You means that a simple config like this can make the trick?
Code: | <VirtualHost *:80>
ServerName sub.domain.com
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://localhost:88/
ProxyPassReverse / http://localhost:88/
ProxyRequests Off
ProxyPreserveHost On
ProxyStatus On
</VirtualHost> |
But what should I use for ServerName? can I keep the same?
Is it correct to simply use http://localhost:88/ (but how can apache know which Virtual Host to use?)?
Shall I use http://sub.domain.com:88 for ProxyPass and ProxyPassReverse instead (as long as port 88 is also opened on the router otherwise the subdomain is not resolved)?
Thank you!
EDIT: I tried with the following settings and I always have the problem of websockets not handled correctly:
Code: | <VirtualHost *:80>
ServerName sub.domain.com
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://sub.domain.com:88/
ProxyPassReverse / http://sub.domain.com:88/
ProxyRequests Off
ProxyPreserveHost On
ProxyStatus On
</VirtualHost> |
The reverse proxy (to the other reverse proxy) is well handled, but it is not able to pass through websockets...
I am ending any hope and resource.. any advice? |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7373 Location: Germany, Next to Hamburg
|
Posted: Fri 04 Dec '15 16:26 Post subject: |
|
|
sub.domain.com:88 works correctly on its own?
Sorry I have only Windows to test this stuff and on windows there no web socket. |
|
Back to top |
|
giopas
Joined: 18 Nov 2015 Posts: 29
|
Posted: Fri 04 Dec '15 17:17 Post subject: |
|
|
Don't apologize, thanks a lot for your support instead!!
Yes, the reverse proxy on port 88 works correctly. |
|
Back to top |
|