LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 04-16-2013, 09:43 PM   #1
xiutuo
Member
 
Registered: Mar 2008
Posts: 55

Rep: Reputation: 15
proxy problem use apache rewrite rules


i want to lead websprider such as google to a backend proxy server 192.168.1.100.
i tried this apache rewrite rules,seems dont work well
PHP Code:
<VirtualHost *:80>
      
DocumentRoot "/usr/local/apache/htdocs"
      
ServerName www.mydomain.com
RewriteEngine On
RewriteCond 
%{HTTP_USER_AGENT} (bot|agent|spider|crawler|extractor) [NC]
RewriteRule ^/(.*) http://192.168.1.100/$1 [P]
</VirtualHost>


<
VirtualHost *:80>

      
ServerName 192.168.1.100
      ProxyRequests Off
<proxy balancer://cluster>
BalancerMember ajp://192.168.1.102:8009 loadfactor=1 route=node102
BalancerMember ajp://192.168.1.103:8009 loadfactor=1 route=node103
BalancerMember ajp://192.168.1.104:8009 loadfactor=1 route=node104
BalancerMember ajp://192.168.1.105:8009 loadfactor=1 route=node105
</proxy>
ProxyPass balancer://cluster/ stickysession=jsessionid nofailover=On
ProxyPassReverse balancer://cluster/
</VirtualHost
thx for your reply.

Last edited by xiutuo; 04-16-2013 at 09:45 PM.
 
Old 04-17-2013, 02:54 PM   #2
warez74
LQ Newbie
 
Registered: Apr 2013
Posts: 27

Rep: Reputation: 0
Hello.

First thing I would do would be adding the entry for 192.168.1.100 in the /etc/hosts, e.g. :

192.168.1.100 proxy1-this-is-local.loc

Then replace all appearances of 192.168.1.100 with proxy1-this-is-local.loc

Don't forget to put:
ServerName proxy1-this-is-local.loc

instead of:
ServerName 192.168.1.100

in the second virtual host.

BTW, you should have one file per virtual host in the /etc/apache2/sites-available/ . Name each virtual host according to the domain name, e.g. mydomain.com
You can enable each host by typing:
a2ensite mydomain.com


Then, try to write the Rewrite conditions like the following:

RewriteEngine On

RewriteLog /var/log/apache2/rewrite.log
RewriteLogLevel 9

RewriteCond %{HTTP_USER_AGENT} ^NameOfFirstBot [OR]
RewriteCond %{HTTP_USER_AGENT} ^NameOfSecondBot [OR]
RewriteCond %{HTTP_USER_AGENT} ^NameOfThirdBot
RewriteRule ^(.*)$ http://proxy1-this-is-local.loc/$1 [P]

Notice that last rule in the RewriteCond set is not appended with logical operator [OR]

Don't forget to debug the /var/log/apache2/rewrite.log

Regards

Last edited by warez74; 04-17-2013 at 02:59 PM. Reason: typo
 
Old 04-19-2013, 01:48 AM   #3
xiutuo
Member
 
Registered: Mar 2008
Posts: 55

Original Poster
Rep: Reputation: 15
thx . i will try it
 
  


Reply



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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] apache rewrite proxy problem deesto Linux - Server 3 10-26-2011 10:00 AM
apache proxy with rewrite problem xiutuo Linux - Server 3 12-01-2010 05:56 AM
How do I get Apache Rewrite to proxy two domains ? anon252 Linux - Server 1 11-28-2008 05:16 AM
Need to work out rewrite rules with proxy-balance mago Linux - Server 0 03-10-2008 06:56 PM
Need help with Apache rewrite rules?? latino Programming 0 12-24-2004 02:09 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 12:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration