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 know that you can't listen to the same port and IP using two different server processes, but apparently this is possible if you allocate a separate IP address to each. Is this the case? I'm contemplating running both ningx and Apache on the same server (I also welcome feedback on whether this is a good idea), basically because ideally I'd like to try switching over to nginx but supposedly its Tomcat support isn't great, so I'm thinking I'd need to keep apache around for that.

Has anyone done something similar; is it recommended, and how do you go about it?

share|improve this question
add comment

2 Answers

Both apache and nginx take arguments for which addresses to listen on; if you want apache on 192.168.1.100 and nginx on 192.168.1.110, you would add the following to the respective conf files:

httpd.conf (or /etc/apache/ports.conf, depending on distro):

listen 192.168.1.100:80

nginx.conf:

server {
    # port to listen on. Can also be set to an IP:PORT
    listen 192.168.1.110:80;
    . . . 
share|improve this answer
add comment

Yes, with 2 IP addresses you could have nginx and apache both listen on port 80. Alternatively you could configure apache to listed on the same IP address but on a different port and have nginx proxy requests to apache for the apache domains.

server {
    listen 1.2.3.4:80;
    server_name apache_domain.com www.apache_domain.com;
    location / {
    proxy_pass http://1.2.3.4:81/;
    proxy_redirect http://1.2.3.4:81/ /; 
    ...

for apache listening on port 81.

share|improve this answer
    
Are there advantages to using a proxy? Seems like this would just add an unnecessary layer of abstraction to the mix. –  Jordan Reiter Jul 1 '11 at 16:29
    
Very helpful, thank you! Obviously not an ideal setup, but I have an unfortunate need to run both web servers on the same IP (as some older applications expect/depend Apache). –  Brian Lacy Jan 5 '13 at 20:22
    
@BrianLacy: You will have to use one as a proxy for the other then. –  Iain Jan 5 '13 at 20:45
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.