Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I recently set up an Ubuntu 12 server (on Rackspace Cloud's next-gen servers). I will be serving about 10 small web apps on this server. Due to how these apps were built, the PHP app need to run on Apache and the Rails apps need to run on Nginx. Rackspace will not allow multiple IPs on a single server. Is it possible to run apache2 and nginx on the same server using the same IP address both on port 80?

The only information I have found involves using nginx to proxy requests to apache for the apache domains. The proxy information I have found mentions only static pages server directly by nginx.

How can I set up my Ubuntu server to run apache2 and nginx on the same server with only 1 IP address?

share|improve this question
What Rails server are you using (passenger, thin, mongrel, etc.)? There's no reason you have to use it in nginx instead of apache, or vice-versa. – Michael Hampton Jan 17 '13 at 19:15
I'm using Thin as the rails server. – Ryan Jan 17 '13 at 19:16
Then you could just have Apache proxy to thin, or have nginx run PHP. No need to have both Apache and nginx. – Michael Hampton Jan 17 '13 at 19:17
I think you can configure both of then on same IP but different ports. – Arash Mousavi Jan 17 '13 at 19:50
@ArashMousavi I will need them both on port 80 – Ryan Jan 17 '13 at 20:01
up vote 5 down vote accepted

On the same port? No.

However, both Apache and Nginx had reverse proxy support. So run one of them on port 80 and the other on another port. Then configure the one on port 80 to reverse proxy requests matching a particular format (one possibility is subdirectories) to the other.

share|improve this answer
Thanks. Can you explain or provide a guide on how to set up nginx to proxy requests across to apache? As noted, the information I found doesn't explain how to do this using both dynamic rails apps on nginx and php apps on apache:… – Ryan Jan 17 '13 at 21:39
That article you linked to is exactly what you need. Configure nginx how you normally would for rails and add a location entry for some subpath to proxy to apache. – longneck Jan 18 '13 at 0:00
I would suggest using nginx as a reverse proxy instead of apache because nginx is light weight. for configuring nginx as reverse proxy – Sameer Jan 18 '13 at 1:56
Thanks. I finally got both servers working using nginx as the reverse proxy and apache2 sitting behind it on I had a few problems with configuration, but this page was a great start:… – Ryan Jan 21 '13 at 18:56

Your Answer


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.