Ethan Blackburn
Ethan Blackburn

Reputation: 497

Can't connect to Django on EC2 instance with nginx/gunicorn

I am trying to browse to my Django site hosted on an EC2 instance with nginx/gunicorn. I have the correct port open(8000) and have bound the ip address(0:8000). I can navigate to the site using lynx in the terminal only when I am logged into the EC2 instance. I cannot browse to the site using the dns:port. Could this be a problem with virtualenv?

I ran ps -ef | grep nginx to make sure nginx was running and received this:

root      4860     1  0 17:36 ?        00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx     4862  4860  0 17:36 ?        00:00:00 nginx: worker process                   
ec2-user  4930  4529  0 17:44 pts/2    00:00:00 grep nginx    

To further add to the confusion, I was able to connect to the site using an apache server a few days ago. However, I was not using virtualenv.

nginx.conf:

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log;
#error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;

pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


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

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

access_log  /var/log/nginx/access.log  main;

sendfile        on;
#tcp_nopush     on;

#keepalive_timeout  0;
keepalive_timeout  65;

#gzip  on;

# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;

server {
    listen       80;
    server_name  _;
    #charset koi8-r;

    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        proxy_pass http://0.0.0.0:8000;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;

    }

    # redirect server error pages to the static page /40x.html
    #
    error_page  404              /404.html;
    location = /40x.html {
        root   /usr/share/nginx/html;
    }

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

Upvotes: 0

Views: 1266

Answers (1)

Joel Burton
Joel Burton

Reputation: 1516

If you can get to the site via lynx on port 8000 when on the EC2, but can't get to it via a different browser across the internet, the problem is definitely not related to anything like "are you in a virtualenv".

Most candidate is that you don't actually have port 8000 unfirewalled, as you think you do.

What happens if you try telnet from a machine across the internet?

telnet yoursite.org 8000

GET / HTTP/1.1
Host: yoursite.org

Can you connect at all? Does it hang? Do you get something back?

Upvotes: 0

Related Questions