1

I currently have a single apache server with several named virtualhosts defined there, all serving on the same IP, on port 80.

However, I have one static virtualhost (a specific domain) I want to serve with nginx. Is this possible without requiring me to setup nginx to forward all requests to the other virtualhosts ?

I really want to avoid that I need to list every single virtualhost in both apache and nginx, it's a recipe for configuration errors...

2 Answers 2

2

You can only have one thing listening on that one IP, port 80. So, you'll use either nginx or apache directly on port 80. Whichever it is, it's up to you.

If you're using nginx in front, you'll need Apache to listen to some other port, and then proxy the other virtual hosts to that Apache. And, of course, if you have Apache in front, you'll need to proxy that domain to your nginx (which will be listening to some other port).

Which method is easier depends on your configuration, though I think nginx in front may have the edge for that.

Update:

In nginx, the virtual host matching is from most specific to least, so if you have two virtual host blocks, where you specific your specific domain and all the related config, and the other being just matching on port 80 without a servername set, you should be able to handle your scenario. If it's a request on your specific domain, you should match that configuration. If the request is on some other domain, it should match on the default virtual host, which you should have it set to proxy to Apache.

2
  • My 2 cents: you can have apache & nginx both listening on port 80, but on different ip addresses. You will just need to setup dns records of domains you are serving to correct ips. Commented Feb 1, 2012 at 20:38
  • Of course, but the OP said he only had one IP. Commented Feb 1, 2012 at 20:39
0

To add to what cjc has already mentioned...

Please remember that Apache has rpaf module installed and configured properly to get the real IP from nginx.

Here is how to setup nginx virtual hosts for the scenario you mentioned...

http { server { server_name www.staticdomain.com; # access_log, error_log directives root /var/www/domain1.com/htdocs; index index.html; } server { server_name _; # default catch_all directive proxy_pass http://127.0.0.1:81; # please change port and IP to suit yours proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_redirect off; } } 

In your apache config file...

# Please change this according to what you set in nginx configuration above Listen 127.0.0.1:81 LoadModule rpaf_module /path/to/mod_rpaf.so RPAFenable On RPAFsethostname On RPAFproxy_ips 127.0.0.1 RPAFheader X-Real-IP 

Thanks.

1
  • That's where I'm struggling. I have tried compiling mod_rpaf, but I can't as I'm missing header files as httpd.h . I'm on debian etch with apache1.3, so quite ancient :s Commented Feb 2, 2012 at 21:22

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.