Web-server – Media server and Web server — same IP address, how to set this up

apache-2.2djangolighttpdvirtualhostweb-server

Hi I'm trying to build a website where users can upload images. I am wanting to have a seperate media server to host the images, so that the web application can point to the images like

mediaserver.mysite.com/test123.jpg

And the webserver

www.mysite.com

What I am wondering is how can this work if both the media server and the web server are sitting behind a router? I.e. there is only one port 80 available so the mediaserver can't be addressed over HTTP.

Also, the user should be able to cal up mediaserver.mysite.com/test123.jpg and view the image

Well ideally the user would call up

www.mysite.com/media/test123.jpg 

But ultimately the media is served from another server that could be located on an entirely different network than mysite.com

EDIT: I'm using Django on Apache for the web server and lighttpd for the media.

THANKS!

Best Answer

This is done regularly. We have dozens of websites all running on the one IP address, and it's not uncommon to run hundreds. Your web server will inspect the hosts header of the request and serve appropriately.

There are two methods to implement this, and they're both the same, but for different web servers. You did not specify which one you used, so here's the three most common:

IIS 5/6

Right-click on your website and go to Properties. Next to "IP Address" (on the Web Site tab), click Advanced. You will see an entry in there for Port 80, with no Host Header Name. Delete this entry.

Click Add, and under TCP Port leave it at 80 (or 443 for SSL), and under Host Header Name enter the name of the website (for example, mediaserver.mysite.com - although example.com is a reserved name exactly for this purpose but never mind). Click OK, and OK to the next screen And you're done. You can now access that website through mediaserver.mysite.com (and only through that, it won't listen on the IP alone any more).

IIS 7

Same as IIS 5/6 except instead of right-clicking the website, you just select it and on the right-hand side menu choose "Bindings"

Apache

I don't configure apache very often, so my memory is very fuzzy, but you use the name-based VirtualHost directive in your httpd.conf. From the apache example documentation:

NameVirtualHost *

<VirtualHost *>
ServerName www.domain.tld
DocumentRoot /www/domain
</VirtualHost>

(I recommend reading the rest of that documentation page if you are using Apache).