I have a django app which can run locally using the standard development environment. I want to now move this to EC2 for production. The django documentation suggests running with apache and mod_wsgi, and using nginx for loading static files.

I am running Ubuntu 12.04 on an Ec2 box. My Django app, "ddt", contains a subdirectory "apache" with ddt.wsgi

import os, sys
apache_configuration= os.path.dirname(__file__)
project = os.path.dirname(apache_configuration)
workspace = os.path.dirname(project)
os.environ['DJANGO_SETTINGS_MODULE'] = 'ddt.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

I have mod_wsgi installed from apt. My apache/httpd.conf contains

NameVirtualHost *:8080

WSGIScriptAlias / /home/jeffrey/www/ddt/apache/ddt.wsgi
WSGIPythonPath /home/jeffrey/www/ddt

<Directory /home/jeffrey/www/ddt/apache/>
<Files ddt.wsgi>
Order deny,allow
Allow from all

Under apache2/sites-enabled

<VirtualHost *:8080>
ServerName www.mysite.com
ServerAlias mysite.com
<Directory /home/jeffrey/www/ddt/apache/>
    Order deny,allow
    Allow from all
LogLevel warn
ErrorLog  /home/jeffrey/www/ddt/logs/apache_error.log
CustomLog /home/jeffrey/www/ddt/logs/apache_access.log combined
WSGIDaemonProcess datadriventrading.com user=www-data group=www-data threads=25
WSGIProcessGroup datadriventrading.com
WSGIScriptAlias / /home/jeffrey/www/ddt/apache/ddt.wsgi

If I am correct, these 3 files above should correctly allow my django app to run on port 8080.

I have the following nginx/proxy.conf file

proxy_redirect              off;
proxy_set_header            Host $host;
proxy_set_header            X-Real-IP $remote_addr;
proxy_set_header            X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size        10m;
client_body_buffer_size     128k;
proxy_connect_timeout       90;
proxy_send_timeout          90;
proxy_read_timeout          90;
proxy_buffer_size           4k;
proxy_buffers               4 32k;
proxy_busy_buffers_size     64k;
proxy_temp_file_write_size  64k;

Under nginx/sites-enabled

server {
  listen 80;
  server_name www.mysite.com mysite.com;
  access_log /home/jeffrey/www/ddt/logs/nginx_access.log;
  error_log /home/jeffrey/www/ddt/logs/nginx_error.log;
  location / {
    include     /etc/nginx/proxy.conf;
  location  /media/ {
   root /home/jeffrey/www/ddt/;

If I am correct these two files should setup nginx to take requests on the HTTP port 80, but then direct requests to apache which is running the django app on port 8080. If i go to mysite.com, all I see is Welcome to Nginx!

Any advice for how to debug this?

  • Could you please post your nginx.conf file? there is some problem with nginx not enabling your host, maybe include line is like include /etc/nginx/conf.d/*.conf; and your config file is not .conf. Any way if you see nginx welcome page means that your config is not applied. – Andrei Mikhaltsov Oct 17 '12 at 17:03
  • For future users, I should mention that with the advent of mod_wsgi-express, we do not need to do any Apache config, no VirtualHost definitions, nothing in conf and sites folders. Its all done in a well-optimized way by mod_wsgi-express automatically. See Graham's blog posts for details – Anupam Jul 4 '17 at 6:46

please note, that you should use www.mysite.com or mysite.com in your requests(as it defined in config file):

server {
  listen 80;
  server_name www.mysite.com mysite.com;

but looks like, You're requesting site by localhost or by IP address


First of all please make sure you can access your application on & please post content of nginx_error.log. Try Copy paste following nginx conf file & check it is working. I am using same config for my python application.

user www-data;
worker_processes 4;
pid /var/run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;

http {

    # Basic Settings

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    # Logging Settings

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    # Gzip Settings

    gzip on;
    gzip_disable "msie6";

    # Virtual Host Configs

    server {
        listen 80;

        location / {
            proxy_pass_header Server;
            proxy_set_header Host $http_host;
            proxy_redirect off;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Scheme $scheme;

    location /static {
        root /home/ubuntu/www/myproject/webapp;


    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;


In your NGINX config, you've included the path to the conf file (/etc/nginx/proxy.conf) inside a location. I believe that it belongs outside.


Firstly, please for the love of all that is holy, don't use both nginx and httpd. This is going to be a pain in the ass to debug.

Secondly, nowhere in the docs have I seen that they recommend this sort of setup.

Use apache or nginx, this will eliminate half of your problems.

Also check your nginx.conf if it's not including files from other dirs, that might have a global vhost that overrides yours.

You should also edit your post to remove the domain in apache config near the WSGI params, as you are currently leaking your production setup.

Remove other sites from sites-enabled.

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.