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.

I'm running a small VPS (512MB-Ubuntu 10.04) and I'm trying to get Nginx to sit at the front and serve all the images/static stuff and only send PHP request to Apache2 when needed. I was wondering do I need to set up a vhost for every site in Nginx and then the same in Apache or is there a better way of doing this?

I've been fighting with it and it just seems to be overly complex.

Cheers, Scott

share|improve this question
add comment

2 Answers 2

You need a vhost in nginx only if you want nginx to respond differently based on the hostname. So, for example, if you ALWAYS want nginx to proxy the request to apache, then no vhost is needed. If you want it to ALWAYS proxy the request to apache if the filename doesn't end in ".png", and/or the requested file doesn't exist in a given directory, then still, you don't need a virtual host.

But if you want nginx to search for files in different locations based on the hostname, then unless there's an easy, straightforward way you can tell nginx to convert the hostname into a file location, then you'll probably end up setting up a virtual host for each hostname -- that way you can tell it where to find the files.

share|improve this answer
add comment

I would create a vhost in both apache and nginx for each. If you really have a lot of vhosts you can probably write a quick shell script to generate one set of initial configurations from the other set.

In the long run, I think this is the simplest option, as it makes it easier to make changes on a site level after the system is configured.

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.