Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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!

share|improve this question
    
Please specify which web server you are using (IIS, Apache, etc) –  Mark Henderson Aug 17 '09 at 3:57
add comment

4 Answers

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).

share|improve this answer
    
Thanks! Now I am hosting them all from the same connection for now because it is what I have, but eventually I will want the media.mysite.com's traffic to be independent from www.mysite.com, how can I work that out? –  SteveM Aug 17 '09 at 4:10
    
Yep. You will do this at your DNS entry. You will still most likely do name-based virtual hosts at your new server, but you will create what's called an A Entry for your subdomain (media.mysite.com) to point to the IP address of your new server. –  Mark Henderson Aug 17 '09 at 4:15
add comment

Sure, you just need to setup name-based virtual hosting on your webserver, so that it knows how to differentiate between the different names ("name-based virtual hosting" plus your OS/webserver in Google should give you plenty of help on the subject).

share|improve this answer
add comment

What you'd need to do is basically set up your "router" as a proxy. It would have to be a full-fledged HTTP server that accepts incoming requests and checks to see whether they're directed to www.mysite.com or mediaserver.mysite.com, and hands off the requests to either the web server or the media server based on that. (It could also do more fine-grained checks, like looking for the path www.mysite.com/media and rewriting that to mediaserver.mysite.com)

If you're not able to actually run an HTTP proxy on the router itself, you should at least be able to configure the router to direct all HTTP traffic (on port 80) it receives to one particular machine which is behind it, and that machine can be your HTTP proxy.

Depending on what kind of a load your website produces, you could make the proxy be the same as the web server, or make the proxy be the same as the media server, and that way you can get away with just two servers, not three. But again, it does depend on how much of a load (and what kind of load) you're putting on these systems.

share|improve this answer
add comment

FYI If you're planning on using Lighttpd I would suggest you go with Nginx instead. It is newer with less of a track record, but is faster and lighter and has already surpassed Lighty in number of sites using it. Nginx is also in use for some really high profile sites like Wordpress, Github and Hulu. I use Nginx as a frontend and to serve static files for an extremely high traffic site and it runs great!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.