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 DocumentRoot "D:/www/test" servername serveralias errorlog "logs/ log "customlog" logs/ 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 </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 </Proxy>

The proxy can be used on the local machine.


1.2 browser settings (taking Firefox as an example)


1.3 access results

Visit and observe the HTTP request response:

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


2. Reverse Proxy 2.1 Apache settings
1 <virtualhost *: 80> 2 serveradmin 3 DocumentRoot "D:/www/test" 4 servername 5 serveralias 6 errorlog "logs/ log "7 customlog" logs/ 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 proxypassreverse/Proxy 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 forward all requests in the domain to the proxy, such as, to the proxy
  • Proxypassreverse/Proxy

The following code is available in

1 <?php2     header('Location:');3 ?>



So in the redirection, Apache will reset the HTTP request to the, this role will be explained later

The following code is available in

1 <?php2     echo 'in <br>';3 ?>



2.2 browser access Effect


  • Apache sends the request to the proxy, HTTP Request

It can be found that the request in the request is still, but it is indeed handled by

  • redirects to

Page display


HTTP Request

You can also see that the request is still

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 instead of, because after proxypassreverse is configured, Apache will adjust it back to when redirection to, apache then proxies to proxypassreverse, even if the program under redirects to another file (such as login. PHP redirects to result. PHP), and you will not find the shadow of 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: 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.