首页  编辑  

Ubuntu 启用和禁用Apache2反向代理

Tags: /计算机文档/Linux & Unix/   Date Created:
How to install mod_proxy and setup reverse proxy in Apache Ubuntu | sharadchhetri
Install mod_proxy and setup reverse proxy in Apache Webserver

Follow the given below steps.
Note: In all given below example replace the value of ServerAdmin,ServerName & ServerAlias as per your server information
Step 1: Install the module
sudo apt-get install libapache2-mod-proxy-html
Step 2: Installing the dependency libxml2-dev
sudo apt-get install libxml2-dev
Step 3: Load the module
a2enmod proxy proxy_http
Step 4: Create the Virtual Host in apache configuration file . If your configuration is located in conf.d you have to do changes in that file. I am giving example with default setting in Apache Webserver in Ubuntu
vi /etc/apache2/sites-enabled/000-default
Paste the below two lines within VirtualHost tag
ProxyPass /foo http://internalwebserver1.example.com/give/path/of-requested-location
ProxyPassReverse /foo http://internalwebserver1.example.com/give/path/of-requested-location
Lets see the configuration of my file,it will clear the doubt
<VirtualHost *:80>
       ServerAdmin sharad@example.com
       ServerName example.com
       ServerAlias example.com
      ProxyPass /foo http://internalwebserver1.example.com/files/webapp
      ProxyPassReverse /foo   http://internalwebserver1.example.com/files/webapp
   
</VirtualHost>
Step 5: Now restart the apache
/etc/init.d/apache2 restart
Step 6: Now Openbrowser in client machine and check the website. 
Done

Now for Scenario 2:
Follow the all above given steps except in Step 4 you have to do below given setting
Below is the reference of my configuration file
<VirtualHost *:80>
       ServerAdmin sharad@example.com
       ServerName openerp.example.com
       ServerAlias openerp.example.com
      ProxyPass / http://openerp.example.com:8069
      ProxyPassReverse / http://openerp.example.com:8069
   
</VirtualHost>
Restart the apache2 and open the browser and check it
/etc/init.d/apache2 restart