2016-05-23 204 views
0

我沒有收到來自ngix(nginx + uwsgi + django)。 nginx的服務器不允許請求打uwsgi服務器

nginx的日誌

2016年5月23日十五時19分49秒[錯誤] 9019任何答覆#0:* 3上行超時(110:連接超時),從上游讀取響應頭,客戶端:122.171.107.80,服務器:54.169.34.178,請求:「GET/HTTP/1.1」,上行:「uwsgi:/ /127.0.0.1:8000「,主機:」54.169.34.178「

以前我只使用uwsgi服務器,現在我想在前面添加nginx,所以t它可以提供靜態數據並充當api-gateway。

我想用這個tutoriall。我能夠獨立運行uwsgi服務器,並且當我將它與nginx結合使用時,它不起作用。

任何人都可以幫我嗎?

user www-data; 
worker_processes 4; 
pid /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; 

    # server_names_hash_bucket_size 64; 
    # server_name_in_redirect 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"; 

    # gzip_vary on; 
    # gzip_proxied any; 
    # gzip_comp_level 6; 
    # gzip_buffers 16 8k; 
    # gzip_http_version 1.1; 
    # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; 

    ## 
    # nginx-naxsi config 
    ## 
    # Uncomment it if you installed nginx-naxsi 
    ## 

    #include /etc/nginx/naxsi_core.rules; 

    ## 
    # nginx-passenger config 
    ## 
    # Uncomment it if you installed nginx-passenger 
    ## 

    #passenger_root /usr; 
    #passenger_ruby /usr/bin/ruby; 

    ## 
    # Virtual Host Configs 
    ## 

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


#mail { 
# # See sample authentication script at: 
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript 
# 
# # auth_http localhost/auth.php; 
# # pop3_capabilities "TOP" "USER"; 
# # imap_capabilities "IMAP4rev1" "UIDPLUS"; 
# 
# server { 
#  listen  localhost:110; 
#  protocol pop3; 
#  proxy  on; 
# } 
# 
# server { 
#  listen  localhost:143; 
#  protocol imap; 
#  proxy  on; 
# } 
#} 

網站啓用/ *。CONF

```

upstream testing { 
server 127.0.0.1:8000; 
} 

server { 
listen  80; 

    server_name 54.169.34.178 
    charset  utf-8; 

    # max upload size 
    client_max_body_size 75M; # adjust to taste 


    location/{ 
     uwsgi_pass testing; 
     include  /home/ubuntu/testDjango/testWeb/uwsgi_params; 
    } 

}

```

+0

你得到這個錯誤,而nginx的是試圖提供靜態內容,而它被代理到你的uwsgi服務器? – avichalp

+0

目前我沒有單獨提供靜態內容。我只是試圖獲得主頁,其中有單個文件 – zakir

+0

http://54.169.34.178:8000/中的所有必要頁面,對我來說運行良好,我正在運行uwsgi。我試圖通過http://54.169.34.178/,但它不起作用 – zakir

回答

0

按的配置和細節,你共享它接縫就像你使用uwsgi服務器綁定到0.0.0.0(因爲你可以在這裏訪問它54.169.34.178:8000),而在你的nginx配置中,你將上行設置爲127.0.0.1。這就是爲什麼nginx無法訪問您的應用程序。

我會建議使用以下命令 uwsgi --http 127.0.0.1:8000 --module testWeb.wsgi

現在嘗試從您的瀏覽器訪問http://54.169.34.178/您在127.0.0.1運行應用程序。

+0

我得到了同樣的錯誤,現在我甚至無法指出uwsgi。當我嘗試Ipadderess:8000/- 它不起作用。 和Nginx拋出相同的錯誤。 – zakir

+0

你試過'uwsgi --http 127.0.0.1:8000 --module testWeb.wsgi'。 這裏ipaddress是不是任何ipaddress,但你本地主機,即127.0.0.1? – avichalp

+0

是的,我做到了(uwsgi --http 127.0.0.1:8000 --module testWeb.wsgi)。我在ec2上跑步,所以只是試圖打到http://54.169.34.178:8000/-,我在這裏做錯了什麼? – zakir

0

uwsgi_pass不是HTTP協議,但uwsgi協議,接受插座不是http

當你uwsgi_pass測試,預計插座,所以你需要在插座模式下運行uwsgi並在其上驗證權限(nginx的應該能閱讀,如果你想保持在端口寫入該文件)

和HTTP你將不得不改變uwsgi_pass到proxy_pass