Apache & Nginx as a reverse proxy, Virtual Hosts?

Hi all, purchased another linode today to experiment with so I don't take my main sites down…

I want to set up Apache and use Nginx as a reverse proxy.

Using this set-up, should I be using Apache or Nginx to set up any virtual hosts?

Thanks in advance for any advice.

9 Replies

You need to set up both, but restrict apache to listen on 127.0.0.1

Thanks, I have both set up & working, just not sure if I should now be using Apache or Nginx config files for the virtual hosts?

You need to configure virtual hosts for both, nginx passes the host header onto apache.

cool, thanks.

So when I add a new virtual server, say anothersite.com, I need to add it to both Apache & Nginx?

Looking at the nginx files, I thought I would just add location of new sites there?

Apache has to know where to serve the files from for that particular site when nginx passes the request on, so you would have to add a virtual host entry to Apache as well.

thanks.

so setting up from start again, I deploy Ubuntu 10.10, followthis tutorial in setting up a LAMP server.

Get virtual hosts working as expected.

Then install Nginx & also add the virtual servers, while I change the apache listening port?

That sounds like a good plan.

http://httpd.apache.org/docs/2.2/vhosts/

http://wiki.nginx.org/VirtualHostExample

Anything serving files from a hard drive (like a web server) will need to know where those files are. So they must define a base directory (for each domain) from which to look for files. Apache (DocumentRoot) and Nginx (root) are configured independently from one another (they do not share configuration information). So both will need to be configured, no matter whether used in conjunction with each other (e.g. proxying) or not.

Only one application can bind to a port for any given IP address. Typically a trivial setup has Nginx listening on the public IP (your linode IP address) serving static items and passing on any other requests to localhost (127.0.0.1) which not visible to the world. And then Apache listening to localhost deals with PHP and passes that result back to Nginx.

Hope that helps a little :)

Depends on how complicated your setup is. You might be able to use one nginx config for all virtual hosts or you might want separate configs.

How many domains, are they all handled identically (same software?) and what is it that you're having nginx do?

If you're going to serve static files directly from nginx, you can put your data in directories named after the domain and use the host variable in the nginx config to let nginx find the files. (i.e. root /var/www/$host/public)

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct