Good Day,

I am currently using the free Amazon EC2 micro instance to learn Linux and server setup.

I wish to setup Nginx as a reverse web proxy. I found a great article on mediatemple on how to do it: http://wiki.mediatemple.net/w/Using_Nginx_as_a_Reverse_Web_Proxy

The directions work for most any server except for EC2.One difference between EC2 and MediaTemple is how IPs work. Overall EC2 instances do not know their elastic IP. So when following the wiki directions in the virtual hosts for instance instead of myip:80 for instance I put *:80. When just using Apache this works perfectly.

In the apache virtual hosts I did "" and in the Nginx I put *:80.

Apache restarts, by Nginx provides an error that it cannot bind because the ip is already in use. If I could add an actual IP in the Nginx file it would work but since EC2 requires me to put in the asterisk it ends up conflicting with the apache virtual hosts entry.

Anyone know a simple way around this (other than not using EC2) ;-) Thank you!

Cheers, Christopher


Your problem has nothing to do with Elastic IPs. The issue is that both Nginx and Apache can't both be listening on Port 80. The simple solution is to change the port that Apache listens on, to 81 or 8080 as examples, while allowing Nginx to listen on port 80 (because when someone types in your URL, you want the request going to Nginx, not straight to Apache).

Basically, what you want to do is go through that tutorial, and whenever you see a reference to Apache and port 80, use a different port like 8080 or 81. Then you need to update your Nginx config to tell it to look for Apache on your new port.

Restart both services and you will be good to go.

  • I should just add, that while it's technically possible to run Apache and Ngnix on the same port like that, it's an insanely silly thing to do :) – BenGC Jan 8 '11 at 19:51
  • Thanks for the response. But why does it work on non EC2 servers when both are set to listen to port 80? It's only not working on EC2 where I can't explicitly put my IP in the Nginx. As for it being an insanely silly thing to do, do you mean you don't understand the performance benefits of it? Nginx serves files much faster than Apache, but of course can't simply use Nginx with most CMS's or plugins that use standard .htaccess. So the reverse proxy servers static files quickly with Nginx and then defaults to Apache for everything else. – cchiera Jan 8 '11 at 21:49
  • I'm not saying that using Nginx is silly. Running them both on the SAME PORT is what I think is silly.It works on their server because you can set per-ip listeners when you know the external IP. When you DON'T know the outside IP, and you only know the internal IP, you can not set up per-IP listeners because and your EC2's 10.x address are interpreted as the same thing. – BenGC Jan 8 '11 at 22:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.