6

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?

Jordan Reiter
  • 1,290
  • 4
  • 20
  • 40

2 Answers2

7

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;
    . . . 
Bryan Agee
  • 1,209
  • 2
  • 11
  • 27
4

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.

user9517
  • 115,471
  • 20
  • 215
  • 297
  • Are there advantages to using a proxy? Seems like this would just add an unnecessary layer of abstraction to the mix. – Jordan Reiter Jul 01 '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 05 '13 at 20:22
  • @BrianLacy: You will have to use one as a proxy for the other then. – user9517 Jan 05 '13 at 20:45