Forum Moderators: phranque

Message Too Old, No Replies

Mod Rewrite , redirect port error !

         

bezildo

2:49 pm on Jan 8, 2009 (gmt 0)

10+ Year Member



Hi guys,

First of all, nice forum =)

Lets go, my scenario is:

Apache:
2 Dns names:
www.domain.com
fv.domain.com

When i access www.domain.com, i need open a static page, in my /var/www/html folder (root or home folder) and its ok, working fine.

But when i access fv.domain.com, i want a redirect for a jboss instance, like:
fv.domain.com:8080/fv/

I using this following Virtual Directory:

<VirtualHost fv.domain.com:80>
servername fv.domain.com.br
RewriteEngine on
RewriteLogLevel 9
ServerSignature on

RewriteCond %{SERVER_PORT} !^8080$
RewriteRule ^/(.*) http://fv.domain.com:8080/fv/$1 [P,NC,L,R]

RewriteLog “/etc/httpd/logs/fv_redirect.log”
CustomLog /etc/httpd/logs/fv_access.log combined
ErrorLog //etc/httpd/logs/fv_error.log
</VirtualHost>

but nothing happen.

The log is created but nothing appear on logs.

When i access fv.domain.com, apache redirect me to www.domain.com

Apache 2.3

Can anyone help me? =/

wildbest

3:35 pm on Jan 8, 2009 (gmt 0)

10+ Year Member



You're using [P] flag. Do you have mod_proxy installed?

bezildo

5:27 pm on Jan 8, 2009 (gmt 0)

10+ Year Member



Yes

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so

Anyone have an idea about this problem? =/

Caterham

6:12 pm on Jan 8, 2009 (gmt 0)

10+ Year Member



Does your virtual host match the request? Do you use IP-based virtual hosting (one IP per <virtualhost>) since I can't see a NameVirtualhost directive. How did you setup your other domain?
Anyway, there's no need for using mod_rewrite here, use ProxyPass and ProxyPassReverse when your virtual host [httpd.apache.org] works as expected.

ProxyPass / http://fv.example.com:8080/fv/
ProxyPassReverse / http://fv.example.com:8080/fv/

[edited by: jdMorgan at 12:54 am (utc) on Jan. 9, 2009]
[edit reason] Repaired formatting, de-linked. [/edit]

bezildo

7:00 pm on Jan 8, 2009 (gmt 0)

10+ Year Member



I just have 1 ip to server.
I just have this virtual host. Everything else is directory.

I trying a new condition, cause i see mine don't mach.

<VirtualHost 192.168.0.1:80>
servername fv.domain.com

RewriteEngine on
RewriteLogLevel 9
ServerSignature on

RewriteCond %{REQUEST_URI} ^/fv/.+
RewriteRule ^/(.*) [fv.domain.com:8080...] [P,NC,L,R]

RewriteLog /etc/httpd/logs/fv_redirect.log
CustomLog /etc/httpd/logs/fv_access.log combined
ErrorLog /etc/httpd/logs/fv_error.logi

</VirtualHost>

But i think it don't mach too, cause i cannot access fv as uri, and as url, fv.domain.com

If i use proxy, the browser will change the address, and my jboss app was made to run in / of the webserver

So i need when people access fv.domain.com, was redirected to fv.domain.com:8080/fv/, but in the browser the address still fv.domain.com.

When people access www.domain.com, still workin the directory that i have today (/var/www/html/).

Any idea?

Caterham

11:38 pm on Jan 8, 2009 (gmt 0)

10+ Year Member



If i use proxy, the browser will change the address

In that case your configuration is wrong or something else issues the redirect but not mod_proxy.

So i need when people access fv.domain.com, was redirected to fv.domain.com:8080/fv/, but in the browser the address still fv.domain.com.

That is not a redirect, it's (reverse) proxy throughput. While you request /, mod_proxy fetches the documents from fv.domain.com/fv/.
Enable
LogLevel debug
, mod_proxy will log some useful information.

I just have 1 ip to server.

Setup two name-based virtual hosts for port 80, one for your main domain and one for fv.

NameVirtualHost *:80
#
<VirtualHost *:80>
servername www.domain.com
DocumentRoot /var/www/html
CustomLog /etc/httpd/logs/access.log combined
ErrorLog /etc/httpd/logs/error.logi
</VirtualHost>
#
<VirtualHost *:80>
servername fv.domain.com
ProxyPass / http://fv.example.com:8080/fv/
ProxyPassReverse / http://fv.example.com:8080/fv/
ProxyPassReverseCookieDomain fv.example.com:8080 fv.domain.com
ProxyPassReverseCookiePath /fv/ /
CustomLog /etc/httpd/logs/fv_access.log combined
ErrorLog /etc/httpd/logs/fv_error.logi
</VirtualHost>

Don't forget to restart apache. If there's still a redirect (HTTP 30x status code to the browser), investigate what causes this. It's not the directive ProxyPass.

BTW - [P,NC,L,R] - this cannot issue a redirect because the check for proxying comes always first.