2

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 127.0.0.1:8080 (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 http://127.0.0.1:8080/;}. 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?

Jason

3 Answers 3

1

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
</VirtualHost>

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

upstream apache {

      server 127.0.0.1:8080 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;
        }
1

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.

-1
NameVirtualHost 127.0.0.1:8080

<VirtualHost 127.0.0.1:8080>
ServerName firstdomain.com
ServerAlias www.firstdomain.com
...
</VirtualHost>

<VirtualHost 127.0.0.1:8080>
ServerName seconddomain.com
ServerAlias www.seconddomain.com
...
</VirtualHost>
1
  • 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 .