2016-09-30 426 views
0

我想部署一個Django實例到ec2。我正在使用nginx和gunicorn的組合來實現這一點。我得到了nginx isntance和gunicorn正確啓動,我能夠讓我的實例運行。但是,當我試圖將影像上傳到我的應用程序的數據庫我遇到這個錯誤在我gunicorn error.log中:connect()失敗(111:連接被拒絕),同時連接到上游,客戶端

連接失敗的-111連接,拒絕,同時,連接到上游

從前端到數據庫的所有api調用都會在控制檯中返回一個500內部服務器。 我的nginx.conf看起來像

default_type  application/octet-stream; 

# 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; 
include /etc/nginx/sites-enabled/*; 
include /etc/nginx/sites-available/*; 
index index.html index.htm; 

server { 
    listen  127.0.0.1:80; 
    listen  [::]:80 default_server; 
    server_name 127.0.0.1; 
    root   /usr/share/nginx/html; 

    # Load configuration files for the default server block. 
    include /etc/nginx/default.d/*.conf; 

    location/{ 
    } 

    # redir 

而且我啓用的站點 - /默認文件

upstream app_server_djangoapp { 
server 127.0.0.1:8000 fail_timeout=0; 

}

服務器{ #EC2實例安全組必須配置爲接受HTTP連接通過80端口 聽80; server_name myec2isntance.com;

access_log /var/log/nginx/guni-access.log; 
error_log /var/log/nginx/guni-error.log info; 

keepalive_timeout 5; 

# path for static files 
location /static { 
    alias xxxxxx; 
} 
location /media { 
    alias xxxxxx; 
} 
location/{ 
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://app_server_djangoapp; 
     break; 
    } 
} 

}

我想大多數人津津樂道的事情 - 將右permissisons的文件夾。改變本地主機爲127.0.0.1等我對這個主題相對較新,所以任何幫助將不勝感激!

謝謝

回答

0

我會建議默認改成這樣:

upstream app_server_djangoapp { 
server 127.0.0.1:8000 max_fails=3 fail_timeout=50; 
keepalive 512; 
} 

- 刪除

keepalive_timeout 5; 

- 爲什麼ü有兩個位置/塊?

location/{ 
    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://app_server_djangoapp; 
     break; 
    } 
} 
+0

哎呀!沒有注意到雙重位置塊。我擺脫了它。現在我沒有看到日誌中的任何內容,但每次我從前端執行POST調用時,都會看到500內部服務器錯誤。 –

+0

這是進步。當你運行Django的開發服務器時,跟蹤是什麼?另外,如果上傳時間超過30秒,Gunicorn將超時。你需要在你的gunicorn命令中使用'--timeout 120'(2分鐘) –

相關問題