无法使用nginx / gunicorn连接到EC2实例上的Django

时间:2014-03-19 18:08:28

标签: django nginx amazon-ec2 gunicorn

我正在尝试使用nginx / gunicorn浏览我在EC2实例上托管的Django站点。我有正确的端口打开(8000)并绑定了IP地址(0:8000)。只有当我登录EC2实例时,我才能在终端中使用lynx导航到该站点。我无法使用dns:port浏览到该站点。这可能是virtualenv的问题吗?

我跑了ps -ef | grep nginx以确保nginx正在运行并收到此信息:

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    

为了进一步增加混乱,几天前我能够使用apache服务器连接到该站点。但是,我没有使用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;
    }

1 个答案:

答案 0 :(得分:0)

如果您在EC2上通过端口8000上的lynx访问该站点,但无法通过互联网上的其他浏览器访问该站点,则问题肯定是 与任何事情无关就像“你是一个虚拟的人”。

大多数候选人都认为你实际上并没有像你认为的那样使用8000端口。

如果您尝试通过互联网从计算机上远程登录,会发生什么?

telnet yoursite.org 8000

GET / HTTP/1.1
Host: yoursite.org

你能连接吗?它挂了吗?你有什么回报吗?