2014-03-19 94 views
0

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

我跑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; 
    } 

回答

0

如果您可以通过猞猁到达现场上的EC2时的8000端口,而是通过在互联网上不同的浏览器不能得到它,问题是绝对是而不是与“你是否在虚拟世界”有关。

大多数候选人是,你实际上没有像你想的那样没有8000端口的防火墙。

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

telnet yoursite.org 8000 

GET/HTTP/1.1 
Host: yoursite.org 

你可以连接吗?它挂了吗?你有东西回来吗?

+0

它只是挂起。通过端口80上的浏览器导航到站点显示nginx页面,指示服务器设置正确。 –

+0

奇怪的是,我几小时前尝试导航到网站。等待它加载大约5分钟后,我只是厌倦了,关闭了我的笔记本电脑。几小时后我打开它,发现该网站已经加载,但我无法再连接 –

+0

因此,它听起来像“gunicorn正常工作”(即,您可以从本地盒子连接到8000端口的独角兽)和“ nginx正在运行并且可以访问“(即,您可以通过80端口连接互联网)。而且他们之间有一些严重的,奇怪的延迟。 –