Apache does reverse proxy server

Source: Internet
Author: User

The Apache agent is divided into forward proxy and reverse proxy:

1 forward Proxy : Clients cannot access the external Web directly, they need to set up a proxy server in the same network as the client, and the client accesses the external Web through the proxy server (requires proxy server in the Client's browser)

Suitable for:

① proxy server for LAN (usually gateway, equivalent to Squid's general Usage)

② access to a restricted network proxy server, such as education network access to some foreign sites need to find an agent


2 Reverse proxy : The client can access the external web, but cannot access the target web, the target web is located within the network of a machine acting as the target Web proxy, the client direct access to the proxy is like accessing the target Web (the agent is transparent to the client, that is, the client does not have to do how to set Do not know the actual access is only agents, thought is the goal of the Visit)

Suitable for:

①IDC a target machine is only open to the internal web, external clients to access, let another machine to do proxy, external direct access to proxy is equivalent to access the target

②IDC the target machine of a special Web service run on an abnormal port such as 9000, and the firewall is only open to 80, at this time proxy mapping to 9000, external access 80 is equivalent to 9000


In this example

Machine 192.168.0.114 is our reverse proxy server.

Apache/2.0.63 running on its 80 port

A virtual host with two domains above

www.a.org

www.b.org

The effects to be achieved are:

Accessing www.a.org is equivalent to accessing another machine 192.168.0.115

Accessing www.b.org is equivalent to accessing the 9000 port of this machine


The proxy function of Apache is implemented by its proxy module. there are two ways to load modules: static and dynamic, which are described separately:

A static load

Static loading, compile the Apache when compiling, compile parameters as Follows:

"./configure" \

"-prefix=/usr/local/apache3" \

"--enable-so" \

"--enable-rewrite" \

"--with-mpm=prefork" \

"--enable-proxy" \ (this parameter is enabled by the proxy Module)

View the list of modules after installation is complete

/usr/local/apache3/bin/httpd-l

Show

Compiled in Modules:

Core.c

Mod_access.c

Mod_auth.c

Mod_include.c

Mod_log_config.c

Mod_env.c

Mod_setenvif.c

Mod_proxy.c

Proxy_connect.c

Proxy_ftp.c

Proxy_http.c

Prefork.c

Http_core.c

.......

Editing a configuration file httpd.conf

In the Virtual host section

Namevirtualhost *:80

<virtualhost *:80>

ServerAdmin [email protected]

ServerName www.a.org

Proxyrequests OFF


<proxy *>

Order Deny,allow

Allow from all

</Proxy>


proxypass/http://192.168.0.115/

proxypassreverse/http://192.168.0.115/

</VirtualHost>

<virtualhost *:80>

ServerAdmin [email protected]

ServerName www.b.org

Proxyrequests OFF


<proxy *>

Order Deny,allow

Allow from all

</Proxy>


Proxypass/http://127.0.0.1:9000/

Proxypassreverse/http://127.0.0.1:9000/

</VirtualHost>

Two dynamic loading

Dynamic Loading: compiled into an already installed Apache (compiled as DSO Module)

Already installed Apache in/usr/local/apache2.

Enter the Apache source module directory to compile

CD httpd-2.0.63/modules/proxy/

/usr/local/apache2/bin/apxs-c-i-a mod_proxy.c proxy_connect.c proxy_http.c proxy_util.c

From the output see Apache modules directory has produced mod_proxy.so, and has been activated in httpd.conf

cd/usr/local/apache2/conf/

Ls.. /modules/saw that there was mod_prxoy.so.

Editing a configuration file

VI httpd.conf

Modify the following

Loading modules

LoadModule Proxy_module modules/mod_proxy.so (this is generated when compilation is Activated)

LoadModule proxy_http_module modules/mod_proxy.so (this sentence is to be added manually)

Part of the virtual host Plus

Namevirtualhost *:80

<virtualhost *:80>

ServerAdmin [email protected]

ServerName www.a.org

Proxyrequests OFF


<proxy *>

Order Deny,allow

Allow from all

</Proxy>


proxypass/http://192.168.0.115/

proxypassreverse/http://192.168.0.115/

</VirtualHost>

<virtualhost *:80>

ServerAdmin [email protected]

ServerName www.b.org

Proxyrequests OFF


<proxy *>

Order Deny,allow

Allow from all

</Proxy>


Proxypass/http://127.0.0.1:9000/

Proxypassreverse/http://127.0.0.1:9000/

</VirtualHost>

Restart Apache in effect

Note:

If you do not add LoadModule proxy_http_module modules/mod_proxy.so, The browser page will not open, the page display

Forbidden

You don't have permission to access/on the This server.

Log Acess_log inside the display

192.168.0.28--[03/jun/2009:16:16:27 +0800] "GET/?sessionid=4293567494722637330&rand=1244014624405& Context=0&page=com.othe

R.ajaxwhowhatupdate&xrand=1244016991554&wwrandid=1244014624405&wwbugid=2341&wwtype=view HTTP/ 1.1 "403 315

Or

192.168.0.28--[03/jun/2009:17:10:32 +0800] "get/http/1.1" 403 315

That's 403 Error.

Log Error_log inside the display

[Wed June 03 17:08:46 2009] [warn] Proxy:no Protocol Handler is valid for the URL/. If you is using a DSO version of Mod_p

roxy, Make sure the proxy submodules is included in the configuration using LoadModule.


This article from "liang childe" blog, Please be sure to keep this source http://iyull.blog.51cto.com/4664834/1864384

Apache does reverse proxy server

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.