title: Nginx, django on ec2 with elastic ip not responding
body: <p>I have a problem with my amazon ec2 instance. I cannot access my django application running on port 8004 from the browser.</p>
  
  <p>I have setup an instance on amazon ec2, installed django and nginx. This is running on ubuntu trusty 14.04. I have a domain on external dns-nameserver and I have correctly pointed that domain to the public elastic ip of my amazon ec2 instance. When I ping the server it works and it shows the public ip.</p>
  
  <p>I've seen similar threads before and in most cases problems with this have been because firewall rules have not been added for specific ports, that is they are not open to the outside world. In my case I made sure that port 22, 80 and 443 were open when I created the instance. I've even made ports 8000 - 8100 open. </p>
  
  <p>Note: Eventually I will make django run with gunicorn but just to test it I'm simply running it by going: manage.py runserver 8004</p>
  
  <p>Here is a snapshot of how my inbound rules look like for open ports on amazon ec2
  <img src="https://i.stack.imgur.com/sQ0dN.png" alt="enter image description here"></p>
  
  <p>Could it be because I'm editing inbound rules after I launched the instance? Isn't that what you're suppose to be able to do?</p>
  
  <p>Nginx is running without problems, I'll post my config below. I have no idea why this doesn't work. I have followed any thread I find on the subject and nothing seems to fix it.</p>
  
  <p>UPDATE: I can now confirm that I can access my django site directly through the ip, by going
  ip:8004. So obviously this is not a problem with the ports but has likely something to do with nginx config or my DNS settings. </p>
  
  <p>My nginx config (I've replaced ip's with x, and the domain with sub.domain.com. I then try to access the site from sub.domain.com)</p>
  
  <pre><code>upstream docko_server {
      server 127.0.0.1:8004 fail_timeout=0;
  }
  
  server {
      server_name sub.domain.com;
      listen xx.xx.xx.xxx:80;
      return 303 https://$host$request_uri;
  }
  
  # HTTPS server
  #
  server {
      listen xx.xx.xx.xxx:443;
      server_name sub.domain.com;
  
      ssl on;
      ssl_certificate ssl/server.crt;
      ssl_certificate_key ssl/server.key;
  
      ssl_session_timeout 5m;
  
      ssl_protocols SSLv3 TLSv1;
      ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP;
      ssl_prefer_server_ciphers on;
  
      client_max_body_size 25M;
  
      access_log /webapps/docko/logs/nginx-access.log;
      error_log /webapps/docko/logs/nginx-error.log;
  
      location /assets/ {
          alias /webapps/docko/docko/staticfiles/;
      }
  
  
      location / {
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  
  
          proxy_set_header Host $http_host;
  
          proxy_redirect off;
  
  
          if (!-f $request_filename) {
              proxy_pass http://docko_server;
              break;
          }
      }
  
  }
  </code></pre>