Topic: run Nginx and Apache at the same time on the same server?

I am not a server admin, nor a deployment expert.  But, I am wondering if running Nginx and Apache on the same box will cause problems.

Basically, I want to deploy my Rails apps to a Nginx, Mongrel cluster stack.  But, I have a requirement to also run Apache for some legacy Perl code, and potentially for SVN.

Also, to complicate matters more, there would be multiple Rails apps and multiple legacy apps.

What's the best practice for something like this?

I have looked and googled for something like this.  No luck.  It's either so easy and obvious that no one bothers to post about it.  Or, no one has done it.

Re: run Nginx and Apache at the same time on the same server?

Long as you have multiple IP addresses theres no reason you could not bind apache to one IP on port 80 and nginx to port 80 on the other IP. I do this in my setup. I guess if you only have one IP Your only option would be to have apache pass certain traffic off to nginx.

Re: run Nginx and Apache at the same time on the same server?

Can you tell where to read more about that?
I've tried to configure both apache and nginx on the same server but with different ips but couldn't because of the same 80 port.

Re: run Nginx and Apache at the same time on the same server?

Yes.  I would also appreciate any links to tutorials for something like this.  I understand how it would work.  But, I just don't know enough server admin magic to make it happen.  Any help would be appreciated?

Re: run Nginx and Apache at the same time on the same server?

Apache will by default use * in a lot of places for example *:80 meaning it will bind to port 80 on every ip bound to that machine. You want to hard code it to a specific ip address. Problem now is a lot of distro's are not shipping standard apache configs and it's hard to tell you exactly what and where to edit but for me there was

/etc/apache/vhosts.d/00_default_vhost.conf


Where you will see a lot of binds to * I hardcoded those to the IP I wanted apache to use. Then there is

/etc/apache/httpd.conf

Listen *:80

Hardcode that like before. For example

Listen 192.168.1.2:80

Then you can tell nginx to use 192.168.1.1:80 and both should work fine. If there is somehow I can help more I would be happy to but Like I said its hard with apache2 from my experience. Not like the good old days when we just had a single httpd.conf smile Check your ssl section to might have issues with port 443 too.

Re: run Nginx and Apache at the same time on the same server?

Thanks! It works fine now.

Re: run Nginx and Apache at the same time on the same server?

is it possible to front nginx before apache and have it pass traffic to apache? i'm wondering whether it would be preferable to have nginx first since it's more lightweight

Re: run Nginx and Apache at the same time on the same server?

@stephenhandley, yeah just do the same method. Instruct apache to use one IP and then nginx another. I currently do this on my dedicated server.

Re: run Nginx and Apache at the same time on the same server?

stephenhandley wrote:

is it possible to front nginx before apache and have it pass traffic to apache? i'm wondering whether it would be preferable to have nginx first since it's more lightweight

You don't need 2 IPs for that, if it is possible for you to setup subdomains, have nginx listen on yoursite.com at port 80, and have nginx redirect data to apache on apache.yoursite.com and with a different port.

but if you have 2 IP, then go for it.

Re: run Nginx and Apache at the same time on the same server?

Was unaware that was possible considering both programs need port 80. I'll have to try that out myself.

Re: run Nginx and Apache at the same time on the same server?

Well by default both apps listen on port 80, but you can put any other port that pleases you. it's not that they need port  80, it's more that the web browsers by default connect to port 80, otherwise you have to specify http://mysite.com:8080