Friday, July 27, 2012

http: couple of ways to forward http requests


if you have a domain name that points to an ip and you want to serve another page...

if hosted on a different machine which also has a public ip, you can easily redirect requests by javascript's window.location
ex.
<script language="JavaScript">window.location="http://x.x.x.x";</script>

or encapsulate the page in an html frame
ex.
<frameset frameborder="NO" cols="100%,*" rows="*" border="0" framespacing="0">
                <frame name="topFrame" scrolling="auto" src="http://x.x.x.x" />
</frameset>


if hosted on a different machine which has no public ip, you can do port forwarding using your firewall
ex.
in iptables forwarding public ip x.x.x.x port 81 to local ip y.y.y.y port 80:
-A PREROUTING -d x.x.x.x -p tcp --dport 81 -j DNAT --to y.y.y.y:80
-A POSTROUTING -d y.y.y.y -p tcp --dport 80 -j SNAT --to x.x.x.x:81


or if you want to serve another domain on the same machine, you can use apache's virtual host
ex.
NameVirtualHost *:80
<VirtualHost *:80>
        ServerName alternate.mydomain.ph
        DocumentRoot /usr/local/apache2/htdocs/alternate
</VirtualHost>

No comments:

Post a Comment

SSH : No matching host key type found. Their offer: ssh-rsa,ssh-dss

Got this while connecting to my mikrotik router via ssh   Unable to negotiate with <ip address> port <ssh port>: no matching hos...