I am trying to setup a reverse proxy system where nginx sits at the front handling all the requests from the internet and apache2 sits at the back handling all the dynamic content. I can setup virtualhost in nginx based on my domains, but because apache2 is listening only on (not outside facing), i'd like to still have virtualhost based on domain (or whatever can be passed from nginx to apache) and change the dynamic content based on it.

Basically, I have a nginx config in sites_available and sites_enabled that basically says for location /{proxy_pass;}. So currently i don't think there is any way of detecting which domain we have on the outside for apache.

I am almost exactly following this guide to set it up: http://tumblr.intranation.com/post/766288369/using-nginx-reverse-proxy So code and others are almost the same.

Any one have any ideas?


3 Answers 3


Add the following to apache ports.conf

NameVirtualHost *:8080
Listen 8080

Then in each domain virtual host:

<VirtualHost *:8080>
     ServerAdmin [email protected]
     ServerName yourdomain.com
     ServerAlias www.yourdomain.com
     DocumentRoot /srv/www/yourdomain.com/public_html
     ErrorLog /srv/www/yourdomain.com/logs/error.log
     CustomLog /srv/www/yourdomain.com/logs/access.log combined

Create a default.conf file in /etc/nginx/sites-enabled and define the upstream server

upstream apache {

      server weight=1 fail_timeout=120s;

In each sites conf file in /etc/nginx/sites-enabled use the upstream server you created in default.conf for the proxy pass:

location ~* *\.php {

                        proxy_pass http://apache;

FurtiveFelon - I tossed "nginx pass host header" into Google and saw quite a few results. The first result from Sameer Parwani's blog seems right up your alley.

# pass along header with reverse proxy requests
proxy_set_header Host $host;

It will be a bit of a pain to configure the virtual hosts in nginx and apache, but that solution should work for you if I understand your requirements correctly.


ServerName firstdomain.com
ServerAlias www.firstdomain.com

ServerName seconddomain.com
ServerAlias www.seconddomain.com
  • Hi, I don't think this solution works, see above for more details of my setup Oct 12, 2010 at 15:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .