Understand the difference between a forward proxy and a reverse proxy

Source: Internet
Author: User
Tags php redirect

The concept of a forward proxy

The forward agent, the legendary agent, works like a springboard,
To put it simply,
I am a user, I cannot access a website, but I can access a proxy server
This proxy server, he can access the site that I can't access
So I first connected to the proxy server and told him that I needed the content that I could not access the site
Proxy server go fetch it back and then return it to me

From the point of view of the website, there is only one record when the proxy server is fetching the content.
Sometimes not know is the user's request, also hides the user's information, depending on the agent does not tell the website

The conclusion is that the forward proxy is a server between the client and the original server (Origin server), in order to get the content from the original server, the client sends a request to the agent and specifies the target (the original server), then the agent forwards the request to the original server and returns the obtained content to the client. The client must make some special settings to use the forward proxy.
Enable the Apache proxy module

A2enmod Proxya2enmod Proxy_http

Configuring the Forward proxy is simple, just add your Apache-configured Vhost host to the browser's proxy option 1.1 Apache configuration httpd-vhosts.conf (under 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.co M-access.log "Common Alias/sublook" d:/www/test/look/sublook/"<directory" D:/www/test "> Options F    Ollowsymlinks allowoverride All Order allow,deny-all </Directory> #正向代理设置 Proxyrequests on Proxyvia in <proxy *> Order Deny,allow deny from all to 127.0 .0.1 </proxy></virtualhost> 

Now look at the forward proxy setting that section
Proxyrequests on: Open Apache forward Proxy
Proxyvia on: Controlling the flow of proxy requests in the proxy server chain
Proxyvia is explained in the official documentation of the citation Apache2.2 as follows:
1. If the default value is set to OFF, no special processing will be taken. If a request or answer contains a "via:" header, it will pass without any modification.
2. If set to on each request and answer will get a "Via:" header to the former host.
3. If set to full, each generated "via:" header will be added to the Apache server version, the "via:" comment domain appears.
4. If set to block, all "Via:" header rows in each proxy request will be deleted. and will not generate a new "Via:" header.
<proxy *>...</proxy>: Used to control who can access your agent

<proxy *>     Order Deny,allow deny from all to     127.0.0.1</proxy>

This is set to native can use the proxy, really use when you set the
1.2 Browser settings (take Firefox as an example)


1.3 Access Effects

To access www.sina.com, observe the HTTP request response:


As you can see, Via:www.test.com, the positive agent has succeeded.

The concept of reverse proxy

Continue with examples:
Example user Access Http://test.me/readme
But there's no Readme page on test.me.
He was secretly taken back from another server and then spit it out to the user as his own content.

But the user does not know

The test.me mentioned here has the reverse proxy function set by the server that corresponds to the domain name.



2.1 Apache settings

<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 Ali As/sublook "d:/www/test/look/sublook/" <directory "D:/www/test" > Options followsymlinks Allowov Erride all Order allow,deny allow from all </Directory> #反向代理设置 proxypass/proxy HT Tp://www.proxypass.com/proxy proxypassreverse/proxy http://www.proxypass.com/proxy </VirtualHost> <virtua     Lhost *:80> ServerAdmin prograsliu@gmail.com documentroot "D:/www/proxypass" ServerName www.proxypass.com  Serveralias proxypass.com <directory "D:/www/proxypass" > Options followsymlinks allowoverride All Order Allow,deny allow from all </Directory> </VirtualHost>

Now look at the reverse proxy settings that section
Proxypass/proxy Http://www.proxypass.com/proxy: Forwards all requests under the Www.test.com/proxy domain to the www.proxypass.com/proxy agent, for example Www.test.com/proxy/login.php will hand over to www.proxypass.com/proxy/login.php agent.
Proxypassreverse/proxy Http://www.proxypass.com/proxy:
The following code is in www.proxypass.com/proxy/login.php:

<?php    Header (' location:http://www.proxypass.com/proxy/result.php ');? >

At the time of redirection, Apache will reset the HTTP request to http://www.test.com/proxy/result.php, which will be explained later
The following code is in www.proxypass.com/proxy/result.php:

<?php    Echo ' in proxypass.com <br> ';? >

2.2 Browser Access effects
Visit www.test.com/proxy/login.php
Apache will submit the request to the Www.proxypass.com/proxy/login.php Agent, HTTP request

You can see that the request is actually www.test.com, but it's actually handled by Www.proxypass.com .
proxypass.com/proxy/login.php Redirect 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, and if you don't add this, the redirect HTTP request will be as follows:


You can see that the get in the request is www.proxypass.com, not www.test.com, because after Proxypassreverse is configured, proxypass.com/proxy/login.php is redirected to proxypass.com/proxy/result.php, Apache will adjust it back to test.com/proxy/result.php, then Apache will test.com/proxy/result.php proxy to Proxypass.com/proxy/result.php, so said after configuring the Proxypassreverse, even if Proxypass.com/proxy under the program has redirected to the other Proxypss.com/proxy Files (such as login.php redirect to result.php), you will not find proxypass.com shadow in the request.

Difference between the two

From the use to say:

A typical use of a forward proxy is to provide access to the Internet for LAN clients within the firewall.
Forward proxies can also use buffering features to reduce network usage.
A typical use of a reverse proxy is to provide the server behind the firewall to Internet users for access.
The reverse proxy can also provide load balancing for multiple servers in the backend, or provide buffering services for servers with slower back-end.

In addition, the reverse proxy can enable advanced URL policies and management techniques so that Web pages that are in different Web server systems exist simultaneously in the same URL space.

From a security standpoint:

A forward proxy allows a client to access any Web site through it and hides the client itself, so you must take security measures to ensure that only authorized clients are serviced.

The reverse proxy is transparent to the outside, and the visitor does not know that he is visiting an agent.

This article explains the difference between the forward proxy and the reverse proxy, and more about the PHP Chinese web.

Related recommendations:

How to build a virtual host using Apache

How to start and monitor through the SH memcached process

About automatically logging in to Google Play download app report

Related Article

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.