Apache Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsSystem AdministrationApache Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 18th, 2002, 04:40 PM
yabby yabby is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 7 yabby User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Angry rewrite virtual hosts in apache

I am trying to find out howto to rewrite some virtual hosts in apache. I have currentlly configured several virtual hosts on my system for two sites with 2 document roots.
ie.:
www.123.com
www.234.com
www.345.com
www.456.com

123.com uses documentroot /docuroot1
456.com uses documentroot /docuroot2

What I would like is to have 234.com and 345.com rewritten to 123.com. So when a user enters http://www.234.com in his browser, the server rewrites it to http://www.123.com and all the links that are used next will also be displayed with www.123.com.

I tried to find something about this in the manuals (http://httpd.apache.org/docs/mod/mod_rewrite.html
http://www.engelschall.com/pw/apache/rewriteguide/)
but all I can find is stuff about rewriting directory structures and that kind of stuff. There is no good example about rewriting domains. Anyone ever done this before?

-maarten

Reply With Quote
  #2  
Old July 18th, 2002, 05:54 PM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,969 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 42 m 50 sec
Reputation Power: 185
you should have followed the link at the bottom of your first URL

http://httpd.apache.org/docs/misc/rewriteguide.html tells you how...
__________________
--
Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more.

Reply With Quote
  #3  
Old July 18th, 2002, 06:27 PM
yabby yabby is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 7 yabby User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
rewrite virtual hosts in apache

Well, I tried the suggestions that are mentioned in that manual. I have edited the virtual hosts section of the virtual host I would like to rewrite. So what I am trying to do here is rewrite 123.abc.com to 234.abc.com. I am probably missing something very simple. When I visit http://123.abc.com/ the browser keeps showing 123.abc.com in stead of changing it into 234.abc.com.....


<VirtualHost *>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /usr/local/apache2/htdocs
ServerName 123.abc.com
ErrorLog logs/dummy-host.example.com-error_log
CustomLog logs/dummy-host.example.com-access_log common
RewriteEngine on
RewriteLog logs/rewritelog.txt
RewriteLogLevel 1
RewriteCond %{HTTP_HOST} !^123\.abc\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{SERVER_PORT} !^80$
RewriteRule ^/(.*) http://234.abc.com:%{SERVER_PORT}/$1 [L,R]
RewriteCond %{HTTP_HOST} !^123\.abc\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://234.abc.com/$1 [L,R]
</VirtualHost>

Reply With Quote
  #4  
Old July 18th, 2002, 08:12 PM
freebsd freebsd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Posts: 5 freebsd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
The domains in your first post are completely different from your second post. That said, if you must obscure your data, make it consistent.

>> is rewrite 123.abc.com to 234.abc.com

Then you don't need a docroot for 123.abc.com. The <VirtualHost> block would then be:
Code:
<VirtualHost *>
   ServerName 123.abc.com
   RewriteEngine on
   RewriteRule ^(.*) http://234.abc.com$1 [R,L]
</VirtualHost>

You also must disable UseCanonicalName by setting it to Off.

Reply With Quote
  #5  
Old July 19th, 2002, 06:19 PM
yabby yabby is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 7 yabby User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thumbs up rewrite virtual hosts in apache

Hey, thanks a lot. That works like a charm.
After searching some more and combining some trick that were mentioned in URLrewrite parts, I came up with this:
<VirtualHost abc.com>
ServerAdmin postmaster@abc.com
DocumentRoot /document/root
ServerName 127.0.0.1
JkMount /*.jsp ajp13
ErrorLog logs/abc.com-error-log
CustomLog logs/abc.com-access_log common
RewriteEngine on
RewriteLog logs/rewritelog.txt
RewriteLogLevel 1
RewriteCond %{HTTP_HOST} ^abc.com$
RewriteRule (.*) http://www.def.com/
</VirtualHost>
<VirtualHost www.abc.com>
ServerAdmin postmaster@abc.com
DocumentRoot /document/root
ServerName 127.0.0.1
JkMount /*.jsp ajp13
ErrorLog logs/abc.com-error-log
CustomLog logs/abc.com-access_log common
RewriteEngine on
RewriteLog logs/rewritelog.txt
RewriteLogLevel 1
RewriteCond %{HTTP_HOST} ^(.*)\.abc.com$
RewriteRule (.*) http://www.def.com/
</VirtualHost>

That one also worked, but now with your suggestion, I could change a 26 line statement into one that only needs 6 lines:

<VirtualHost 127.0.0.1>
ServerName abc.com
ServerAlias abc.com *.abc.com
RewriteEngine on
RewriteRule ^(.*) http://www.def.com$1 [R,L]
</VirtualHost>

thank you for your help.

maarten

Reply With Quote
  #6  
Old July 19th, 2002, 09:38 PM
freebsd freebsd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Posts: 5 freebsd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
>> into one that only needs 6 lines

Because you are redirecting that entire vhost to elsewhere, therefore, a docroot for that vhost is not even needed.

BTW, if you change
Code:
RewriteRule ^(.*) http://234.abc.com$1 [R,L]
to
Code:
RewriteRule ^(.*) http://192.168.0.2$1 [P,L]
your vhost will then be acted as a reverse proxy.

Reply With Quote
  #7  
Old July 20th, 2002, 04:52 AM
yabby yabby is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 7 yabby User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Lightbulb rewrite virtual hosts in apache

Hey, that's nice . Thanks!

|-----------|
|------------------| WEBA |
| |-----------|
|---------|
| GW |
|---------|
| |-----------|
|------------------| WEBB |
|----------|

So let's say I have got a leyout like above. WEBA is 10.2.3.1 and WEBB is 10.2.4.1. Now when I install apache with mod_ssl on the gateway, I can have it fetch the pages from WEBA and WEBB for me and present them using HTTPS to my client. Now if I am correct: you can not use this when you are using virtual hosting on WEBA and WEBB right? Because then it would send the user that's before the GATEWAY, directly to an internal IP in stead of proxying...

I was wondering about one thing though. Can I also have https://web.abc.com/WEBA send to WEBA and https://web.abc.com/WEBB to WEBB....

maarten

Reply With Quote
  #8  
Old July 20th, 2002, 09:38 AM
freebsd freebsd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Posts: 5 freebsd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
If I understand you correctly, yes, you can run a reverse proxy frontend on your HTTPS vhost while the backend (the proxied host) uses HTTP.
Code:
<IfDefine SSL>
  <VirtualHost 12.34.56.78:443>
    ServerName warez.domain.com
    ServerAdmin webmaster@domain.com
    SSLEngine on
    SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
    SSLCertificateFile    /etc/ssl/server.crt
    SSLCertificateKeyFile /etc/ssl/private/server.key
    SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0
    <Files ~ "\.(cgi|shtml)$">
      SSLOptions +StdEnvVars
    </Files>
    RewriteEngine on
    RewriteOptions inherit
    RewriteCond %{HTTP_HOST} !^warez\.domain\.com$ [NC]
    RewriteRule ^(.+) /var/www/htdocs/error.cgi [T=application/x-httpd-cgi,L]
    RewriteRule ^/icons/(.+) - [PT,L]
    RewriteRule ^(.*) http://192.168.0.6/warez$1 [P,L]
    CustomLog /var/log/warez_log log_this env=!dont_log
  </VirtualHost>
</IfDefine>

With this, session from public to https://warez.domain.com at 12.34.56.78:443 is encrypted. Say my 12.34.56.78 box also has another NIC with 192.168.0.1. So between 192.168.0.1 and 192.168.0.6, it's unprotected and in cleartext. But there's no security flaw since those are LAN traffic and not sniff'able with my firewall setup.

Reply With Quote
  #9  
Old July 20th, 2002, 10:06 AM
yabby yabby is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 7 yabby User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
rewrite virtual hosts in apache

Well, it was partially what I meant. What I was thinking about was redirecting visitors based on the subdirectory they are accessing. An example:

john enters:
http(s)://abc.def.com/john and will be browsing to internal host 1

mary enters:
http(s)://abc.def.com/mary and will be browsing to internal host 2

or:
http(s)://1.2.3.4/john/index.html = http://10.2.3.4/index.html
and:
http(s)://1.2.3.4/mary/index.html = http://10.2.4.5/index.html

maarten

Reply With Quote
  #10  
Old July 21st, 2002, 06:08 AM
freebsd freebsd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Posts: 5 freebsd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Then you just have to change
Code:
RewriteRule ^(.*) http://192.168.0.6/warez$1 [P,L]
to:
Code:
RewriteRule ^/john(.*) http://10.2.3.4$1 [P,L]
and create another rule for mary respectively.

Reply With Quote
  #11  
Old July 21st, 2002, 06:49 AM
yabby yabby is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 7 yabby User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
rewrite virtual hosts in apache

Never knew it was that simple to use apache for this kind of stuff. Do you know if there is a work arround for virtual hosting? This is all IP based, and if I understand correctly: as soon as you start using domain-names in stead of IP addresses, apache starts redirecting in stead of proxying.

What I am thinking of for example is:
Say I have an apache server and an IIS server. The IIS server is hosting 50 domains on 1 IP address. What I would like to do is connect the apache server to the internet and have it act as a reverse proxy for the IIS server.

So there is:
apache 5.5.5.5
IIS: 10.10.1.1 - www.123.com, www.234.com, .... www.999.com

So I probably have to put those 50 domains into apache as well, but how do I get to proxy it to the W2K machine

Does IIS know how to react by hostheader? Or does apache replaces that with an IP on rewrite?

I am quite surpries by the way that this rewriting is this powerfull. Have quite some new tricks (well for me at least) to try next week....

Reply With Quote
  #12  
Old July 21st, 2002, 07:55 AM
freebsd freebsd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Posts: 5 freebsd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
The only requirement is that, your Apache must be able to talk to your IIS, and those 50 fake FQDNs MUST be resolvable to Apache and IIS. You may run a DNS server for your LAN or use just the same /etc/hosts file on both boxes.

>> Or does apache replaces that with an IP on rewrite?

Like I said, so long as your Apache be able to resolve google.com and yahoo.com, you can change your two lines to be:
Code:
RewriteRule ^/google(.*) http://www.google.com$1 [P,L]
RewriteRule ^/yahoo(.*) http://www.yahoo.com$1 [P,L]
I used IP as an example because it's much faster. If there are 50 vhosts on IIS then you can't use IP only.

Reply With Quote
  #13  
Old July 21st, 2002, 09:08 AM
yabby yabby is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 7 yabby User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Great! Hey, thanks for all your help. Going to enable and disable some switches myself now. Let's see what I can make of it.

maarten

Reply With Quote
Reply

Viewing: Dev Shed ForumsSystem AdministrationApache Development > rewrite virtual hosts in apache


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This