反向代理:指以代理服务器来接受internet上的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到的结果返回给internet上请求连接的客户
在客户无感知的情况下,代理服务器就处理了所有的客户请求。
开启代理分为以后步骤:
一、开启Apache代理模块
LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_connect_module modules/mod_proxy_connect.so LoadModule proxy_ftp_module modules/mod_proxy_ftp.so LoadModule proxy_http_module modules/mod_proxy_http.so
vim httpd.conf
二、配置虚拟机文件
Listen 8083 <VirtualHost *:8083> ServerAdmin webmaster@dummy-host.example.com DocumentRoot "/usr/local/apache/www/8083" DirectoryIndex index.php ServerName localhost:8083 #反向代理 #ProxyPass /proxy http://172.28.66.194:8084/proxy #ProxyPassReverse /proxy http://172.28.66.194:8084/proxy #ServerAlias www.dummy-host.example.com ErrorLog "/usr/local/apache/www/8083/logs/dummy-error_log" CustomLog "/usr/local/apache/www/8083/logs/dummy-access_log" combined </VirtualHost>
再看看8084的配置:
Listen 8084 <VirtualHost *:8084> ServerAdmin webmaster@dummy-host.example.com DocumentRoot "/usr/local/apache/www/8084" DirectoryIndex index.php ServerName localhost:8084 #ServerAlias www.dummy-host.example.com ErrorLog "/usr/local/apache/www/8084/logs/dummy-error_log" CustomLog "/usr/local/apache/www/8084/logs/dummy-access_log" combined </VirtualHost>
注:代理文件只能写在VirtualHost 中,不能放在.htaccess 文件中。会报错