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

share|improve this question
add comment

3 Answers 3

up vote 1 down vote accepted

Add the following to apache ports.conf

NameVirtualHost *:8080
Listen 8080

Then in each domain virtual host:

<VirtualHost *:8080>
     ServerAdmin info@yourdomain.com
     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;
        }
share|improve this answer
add comment

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.

share|improve this answer
add comment
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>
share|improve this answer
    
Hi, I don't think this solution works, see above for more details of my setup –  FurtiveFelon Oct 12 '10 at 15:44
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.