Configure forward proxy and reverse proxy for Apache

Source: Internet
Author: User
Document directory
  • 1.1 Apache configuration httpd-vhosts.conf (in Windows as an example)
  • 1.2 browser settings (taking Firefox as an example)
  • 1.3 access results
  • 2.1 Apache settings
  • 2.2 browser access Effect
1. Forward proxy

Configuring the forward proxy is simple. You only need to add the vhost configured by Apache to the proxy option of the browser.

 

1.1 Apache configuration httpd-vhosts.conf (in Windows as an example)
<Virtualhost *: 80> serveradmin prograsliu@gmail.com DocumentRoot "D:/www/test" servername www.test.com serveralias test.com errorlog "logs/test.com-error. log "customlog" logs/test.com-access. log "common alias/sublook" D:/www/test/look/sublook/"<directory" D:/www/test "> options followsymlinks AllowOverride all order allow, deny allow from all </directory> # Set proxyrequests on proxyvia on <proxy *> order deny, allow deny from all allow from 127.0.0.1 </Proxy> </virtualhost>

 

 

Now let's look at the section set by the forward proxy.

  • Proxyrequests on: Enable Apache forward proxy
  • Proxyvia on: controls the flow of proxy requests in the proxy server chain

The description of proxyvia in the official apache2.2 document is as follows:

    1. If it is set to the default valueOff, Will not take special processing. If a request or response contains"Via:"Header, which will be passed without any modification.
    2. If it is setOnEach request and response correspond to the current host and get"Via:"Header.
    3. If it is setFull, Each generated"Via:"The Apache server version will be added to the header,"Via:"Comment field appears.
    4. If it is setBlock, All"Via:"The first line will be deleted. There will be no new"Via:"Header.
  • <Proxy *>... </Proxy>: used to control who can access your proxy.
1 <Proxy *>2     Order deny,allow3     Deny from all4     Allow from 127.0.0.15 </Proxy>

The proxy can be used on the local machine.

 

1.2 browser settings (taking Firefox as an example)

 

1.3 access results

Visit www.sina.com and observe the HTTP request response:

We can see that via: www.test.com, the forward proxy is successful.

 

2. Reverse Proxy 2.1 Apache settings
1 <virtualhost *: 80> 2 serveradmin prograsliu@gmail.com 3 DocumentRoot "D:/www/test" 4 servername www.test.com 5 serveralias test.com 6 errorlog "logs/test.com-error. log "7 customlog" logs/test.com-access. log "common 8 alias/sublook" D:/www/test/look/sublook/"9 <directory" D:/www/test "> 10 options followsymlinks11 AllowOverride all12 order allow, deny13 allow from all14 </directory> 15 16 # reverse proxy setting 17 proxypass/Proxy http://www.proxypass.com/proxy18 proxypassreverse/Proxy http://www.proxypass.com/proxy19 20 </virtualhost> 21 22 <virtualhost *: 80> 23 Server Admin prograsliu@gmail.com24 DocumentRoot "D:/www/proxypass" 25 servername www. proxypass. com26 serveralias proxypass. com27 <directory "D:/www/proxypass"> 28 options followsymlinks29 AllowOverride all30 order allow, deny31 allow from all32 </directory> 33 </virtualhost>

 

 

Now let's look at the section on reverse proxy settings.

  • Proxypass/Proxy http://www.proxypass.com/proxy: forward all requests in the www.test.com/proxy domain to the www.proxypass.com/proxy proxy, such as www.test.com/proxy/login.php, to the www.proxypass.com/proxy/login.php proxy
  • Proxypassreverse/Proxy http://www.proxypass.com/proxy:

The following code is available in www.proxypass.com/proxy/login.php:

1 <?php2     header('Location: http://www.proxypass.com/proxy/result.php');3 ?>

 

 

So in the redirection, Apache will reset the HTTP request to the http://www.test.com/proxy/result.php, this role will be explained later

The following code is available in www.proxypass.com/proxy/result.php:

1 <?php2     echo 'in proxypass.com <br>';3 ?>

 

 

2.2 browser access Effect

Visit www.test.com/proxy/login.php

  • Apache sends the request to the www.proxypass.com/proxy/login.php proxy, HTTP Request

It can be found that the request in the request is still www.test.com, but it is indeed handled by www.proxypass.com

  • Proxypass.com/proxy/login.php redirects to proxypass.com/proxy/result.php

Page display

In proxypass.com

HTTP Request

You can also see that the request is still www.test.com/proxy/result.php

This is where proxypassreverse works. If this item is not added, the HTTP request will be shown in the following figure after redirection:

 

It can be found that the get in the request is www.proxypass.com instead of www.test.com, because after proxypassreverse is configured, Apache will adjust it back to test.com/proxy/result.php when redirection to proxypass.com/proxy/result.php, apache then proxies test.com/proxy/result.php to proxypassreverse, even if the program under proxypass.com/proxy redirects to another proxypss.com/proxy file (such as login. PHP redirects to result. PHP), and you will not find the shadow of proxypass.com in the request.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.