I have a webserver that is currently running in Apache with some virtualhosts... I would to deploy my django application in this server. But, I would like to use Nginx. (I cant migrate all my virtualserver to Nginx in this moment). So my question is... Can I have Apache and Nginx running in the same server? How can I do that? I have a specific hostname (virtualhost) that my django application will "answer".


migrated from stackoverflow.com Aug 1 '11 at 0:25

This question came from our site for professional and enthusiast programmers.


Here is a deploy workshop where they do exactly what you are looking for (except that they don't use virtual hosts)

In resume they do a light heavy approach where nginx takes the first request and proxy them to apache or responses an error in case of one. They talk about other stuff like db replication, fabric, etc. Its pretty much worth seeing it


Make nginx listen on different port than Apache and (assuming that Apache is your main server) create VirtualHost that proxies requests to nginx. But I think it's not the best solution - you'll have to connect Django to nginx with FastCGI (or something similar) and you'll end with three servers (Apache, nginx, django fastcgi) instead of just one (Apache with mod_wsgi).


When possible I believe it is better to put nginx out in front -- i.e. have it answer at port 80. Configure it so that it is handling all of your non-Django requests, including images, CSS, JS, etc. It is very lightweight and is lightning fast. nginx does not directly support any scripting environements (which is why it is so small and fast), so anything you have that wants/needs an Apache environment can be handled via FastCGI.

WebFaction (a hosting company that I am a happy customer of) does it this way and I have been very impressed with the performance of Django sites in a shared hosting environment.

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.