47359

using apache2 as reverse-proxy

background problem: only have one ip public, but have multiple server machine

this will solve how to using multiple sub domain to single ip public with multiple server behind.

using ubuntu server as reverse proxy (192.168.0.206), io.domain.gw (192.168.0.214), api.domain.gw (192.168.0.90)

——– stucture ——

io.domain.gw  [internet] —> [ip my.ip.pub.lic] –> [proxy 192.168.0.206] –> [io 192.168.0.214]

api.domain.gw  [internet] —> [ip my.ip.pub.lic] –> [proxy 192.168.0.206] –> [api 192.168.0.90]

————————————————————————
@proxy: 192.168.0.206
————————————————————————

sudo a2enmod ssl
sudo a2enmod proxy
sudo a2enmod proxy_balancer
sudo a2enmod proxy_http

sudo nano /etc/apache2/sites-available/api-domain-gw.conf
#input
<VirtualHost *:80>    
        ServerName api.domain.gw    
        <Proxy *>
                Order deny,allow
                Allow from all
        </Proxy>    
        <Location />
                ProxyPass http://192.168.0.90/
                ProxyPassReverse http://192.168.0.90/
        </Location>    
</VirtualHost>

sudo nano /etc/apache2/sites-available/io-domain-gw.conf
#input
<VirtualHost *:80>    
        ServerName io.domain.gw    
        <Proxy *>
                Order deny,allow
                Allow from all
        </Proxy>    
        <Location />
                ProxyPass http://192.168.0.214/
                ProxyPassReverse http://192.168.0.214/
        </Location>    
</VirtualHost>
sudo service apache2 restart

————————————————————————
@io: 192.168.0.214
————————————————————————

sudo nano /etc/apache2/conf-available/servername.conf 
# inputkan
ServerName io.domain.gw

sudo nano /var/www/html/index.php
# input
<?php
header('Content-Type: text/plain');
echo "Server IP: ".$_SERVER['SERVER_ADDR'];
echo "\nClient IP: ".$_SERVER['REMOTE_ADDR'];
echo "\nX-Forwarded-for: ".$_SERVER['HTTP_X_FORWARDED_FOR'];
?>

————————————————————————
@io: 192.168.0.90
————————————————————————

sudo nano /etc/apache2/conf-available/servername.conf 
# inputkan
ServerName api.domain.gw

sudo nano /var/www/html/index.php
# input
<?php
header('Content-Type: text/plain');
echo "Server IP: ".$_SERVER['SERVER_ADDR'];
echo "\nClient IP: ".$_SERVER['REMOTE_ADDR'];
echo "\nX-Forwarded-for: ".$_SERVER['HTTP_X_FORWARDED_FOR'];
?>

Published by

G3n1k

just to remember what i had known :)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s