2011-07-12 155 views
13

我運行Ubuntu 10.04,Django 1.3,Nginx 0.8.54和uWSGI 0.9.7。Django + Nginx + uWSGI = 504網關超時

Nginx和uWSGI加載都沒有錯誤。但是,當您訪問我的站點時,它會持續很長時間,然後最終會加載「504 Gateway Time-out」錯誤。

這裏是我的Nginx虛擬主機的conf文件:

server { 
listen   80; 
server_name  www.mysite.com mysite.com; 
error_log  /home/mysite/log/error.log; 
access_log  /home/mysite/log/access.log; 

location/{ 
    auth_basic "Restricted"; 
    auth_basic_user_file /home/mysite/public/passwd; 
    include uwsgi_params; 
    uwsgi_pass unix:///home/mysite/public/myapp.sock; 
} 

location /media { 
    alias /home/mysite/public/myapp/media; 
} 


error_page 401 /coming_soon.html; 

location /coming_soon.html { 
    root /home/mysite/public/error_pages/401; 
} 

location /401/images { 
    alias /home/mysite/public/error_pages/401/images; 
} 

location /401/style { 
    alias /home/mysite/public/error_pages/401/style; 
} 

}

我的網站日誌顯示此:

SIGPIPE: writing to a closed pipe/socket/fd (probably the client disconnected) on request/!!! 

我的錯誤日誌顯示此:

upstream timed out (110: Connection timed out) while reading response header from upstream 

我有兩個此服務器上的其他站點具有相同的配置,並且它們的加載非常完美。

有其他人遇到過這個問題嗎?這裏有幾個線程與我的問題類似,我嘗試了幾個這樣的解決方案,但似乎沒有任何工作。

非常感謝您的幫助!

+0

爲uWSGI添加配置。我想這裏的路徑有問題'uwsgi_pass unix:///home/mysite/public/myapp.sock;' – nk9

回答

1

unix:///home/mysite/public/myapp.sock; 語法不正確,請使用像這樣的:

unix:/home/mysite/public/myapp.sock;

19

當請求超過NGINX uwsgi_read_timeout設置時,會產生該錯誤。 NGINX超過此限制後,它關閉套接字,然後uWSGI嘗試寫入關閉的套接字,產生從uWSIG中看到的錯誤。

確保您的NGINX超時至少與uWSGI超時(HARAKIRI_TIMEOUT)一樣高。

+0

爲了澄清,您需要在相應的'location'部分中添加'uwsgi_read_timeout 600;'。 – serg

+0

男人,...我正在敲我的頭3個小時,試圖在nginx中設置任何參數。謝謝! –