Tutorial: Apache as a reverse proxy server

888u

Last update at :2024-05-28,Edit by888u

Tutorial:apache as a reverse proxy server

Redirected earlier: Tutorial: Nginx (LNMP) reverse proxy configuration tutorial Then switch to apache

Source: http://yahoon.blog.51cto.com/13184/162922/

1 Forward proxy: The client cannot directly access the external web. A proxy server needs to be set up in the network where the client is located. The client accesses the external web through the proxy server. web (needs to set up a proxy server in the client's browser) Applicable to: ①Proxy server of LAN (usually gateway, equivalent to the general usage of Squid) ② Access a proxy server on a restricted network. For example, if the Education Network accesses some foreign websites, you need to find a proxy. 2 Reverse proxy: The client can access the external web, but cannot access the target web. A machine in the network where the target web is located acts as a proxy for the target web. The client Directly accessing the proxy is just like accessing the target web (this proxy is transparent to the client, that is, the client does not need to do any settings, and does not know that it is only the proxy that is actually accessed, thinking that it is the target of the access) Applicable to: ① A certain target machine of IDC only opens the web internally. If external clients want to access it, let another machine act as a proxy. Direct external access to the proxy is equivalent to accessing the target. ② A special web service on the target machine of IDC runs on an abnormal port such as 9000, and the firewall only opens 80 to the outside world. At this time, proxy mapping can be done on 80 to 9000. External access to 80 is equivalent to 9000. The simple diagram is as follows In this case Machine 192.168.0.114 is our reverse proxy server apache/2.0.63 runs on its port 80 There are two virtual hosts with domain names on it www.a.org www.b.org The effect to be achieved is: Visiting www.a.org is equivalent to accessing another machine 192.168.0.115 Visiting www.b.org is equivalent to accessing port 9000 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 explained here: 1 static loading Static loading is compiled when compiling apache. The compilation parameters are as follows: "./configure" \ "-prefix=/usr/local/apache3" \ "--enable-so" \ "--enable-rewrite" \ "--with-mpm=prefork" \ “–enable-proxy” \ (This parameter is the proxy module enabled) View the module list 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 …. Edit the configuration file httpd.conf In the virtual host section NameVirtualHost *:80 ServerAdmin webmaster@dummy-host.example.com ServerName www.a.org ProxyRequests Off Order deny,allow Allow from all ProxyPass/http://192.168.0.115/ ProxyPassReverse/http://192.168.0.115/ ServerAdmin webmaster@dummy-host.example.com ServerName www.b.org ProxyRequests Off Order deny,allow Allow from all ProxyPass/http://127.0.0.1:9000/ ProxyPassReverse/http://127.0.0.1:9000/ 2. Dynamic loading Dynamic loading: compiled into an already installed apache (compiled into a dso module) The installed apache is in /usr/local/apache2 Enter the module directory of the apache source code 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, we can see that mod_proxy.so has been generated in the modules directory of apache and has been activated in httpd.conf cd /usr/local/apache2/conf/ ls ../modules/ shows that there is indeed mod_prxoy.so Edit configuration file vi httpd.conf Modify as follows Load module LoadModule proxy_module modules/mod_proxy.so (this sentence is generated during compilation and activation) LoadModule proxy_http_module modules/mod_proxy.so (this sentence needs to be added manually) Add the virtual host part NameVirtualHost *:80 ServerAdmin webmaster@dummy-host.example.com ServerName www.a.org ProxyRequests Off Order deny,allow Allow from all ProxyPass/http://192.168.0.115/ ProxyPassReverse/http://192.168.0.115/ ServerAdmin webmaster@dummy-host.example.com ServerName www.b.org ProxyRequests Off Order deny,allow Allow from all ProxyPass/http://127.0.0.1:9000/ ProxyPassReverse/http://127.0.0.1:9000/ Restart apache to take effect Note: If LoadModule proxy_http_module modules/mod_proxy.so is not added, the browser page cannot be opened and the page displays Forbidden You don’t have permission to access / on this server. The log acess_log shows 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 i.e. 403 error The log error_log shows [Wed Jun 03 17:08:46 2009] [warn] proxy: No protocol handler was valid for the URL /. If you are using a DSO version of mod_p roxy, make sure the proxy submodules are included in the configuration using LoadModule.

Recommended site search: IP reverse domain name, asp host space, registration space, free space application, space rental, host discount code, free asp space application to check IP, host space, mysql virtual host,

Tutorial: Apache as a reverse proxy server

All copyrights belong to 888u unless special state
取消
微信二维码
微信二维码
支付宝二维码