You said it happens immediately after you restart the site with that script.  Maybe manage.py is taking some time to initialize the unix domain socket and ultimately call listen() on it.  Until that happens, nginx would not be able to connect() to the socket.<br>
<br><div class="gmail_quote">On Thu, Jun 18, 2009 at 12:54 AM, vanderkerkoff <span dir="ltr">&lt;<a href="mailto:nginx-forum@nginx.us">nginx-forum@nginx.us</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I&#39;m on ubuntu hardy heron, 2.6.24-19-server 64 bit<br>
nginx/0.5.33<br>
django 1.0.2<br>
Python 2.5.2<br>
mysql 5.0.51a-3ubuntu5.4<br>
<br>
Here&#39;s how I installed everything<br>
<br>
<a href="http://pastie.org/515408" target="_blank">http://pastie.org/515408</a><br>
<br>
Here&#39;s how I restart my django app<br>
<br>
#!/bin/sh<br>
if [ -f /var/www/django/conf/pid/$1.pid ]; then<br>
        echo stopping $1 site<br>
  kill `cat /var/www/django/conf/pid/$1.pid`<br>
else<br>
        echo $1 was not running<br>
fi<br>
/usr/bin/python /var/www/django//$1/manage.py runfcgi method=prefork minspare=1 maxspare=1 socket=/var/www/django/conf/sockets/$1.sock pidfile=/var/www/django/conf/pid/$1.pid<br>
chmod 777 /var/www/django/conf/sockets/$1.sock<br>
<br>
Here&#39;s the server directive in the /etc/nginx/sites-available/default file<br>
server<br>
{<br>
    listen   80;<br>
    server_name $<a href="http://1.com" target="_blank">1.com</a>;<br>
    access_log /var/www/django/log/access.log;<br>
    error_log /var/www/django/log/error.log error;<br>
    location /<br>
    {<br>
        fastcgi_pass unix:/var/www/django/conf/sockets/$1.sock;<br>
        fastcgi_param SERVER_NAME $server_name;<br>
        fastcgi_param SERVER_PORT $server_port;<br>
        fastcgi_param SERVER_PROTOCOL $server_protocol;<br>
        fastcgi_param PATH_INFO $fastcgi_script_name;<br>
        fastcgi_param REQUEST_METHOD $request_method;<br>
        fastcgi_param QUERY_STRING $query_string;<br>
        fastcgi_param CONTENT_TYPE $content_type;<br>
        fastcgi_param CONTENT_LENGTH $content_length;<br>
        fastcgi_pass_header Authorization;<br>
        fastcgi_intercept_errors off;<br>
    }<br>
}<br>
<br>
Here&#39;s the /etc/nginx/nginx.conf<br>
user username groupname;<br>
worker_processes  6;<br>
error_log  /var/log/nginx/error.log;<br>
pid        /var/run/nginx.pid;<br>
events {<br>
    worker_connections  1024;<br>
}<br>
http {<br>
    include       /etc/nginx/mime.types;<br>
    default_type  application/octet-stream;<br>
    access_log  /var/log/nginx/access.log;<br>
    sendfile        on;<br>
    #tcp_nopush     on;<br>
    #keepalive_timeout  0;<br>
    keepalive_timeout  65;<br>
    tcp_nodelay        on;<br>
    gzip  on;<br>
    include /etc/nginx/sites-enabled/*;<br>
}<br>
<br>
Every now and then the web site returns a 502 bad gateway error. It&#39;s a very small site with hardly any traffic, so  resources are not a problem.  It usually happens immediately after I restart the site with the script above, I&#39;m wondering if the restarting is a problem.<br>

<br>
Here&#39;s what nginx says about it, running in error mode<br>
<br>
2009/06/17 17:09:22  17715#0: *10888 connect() to unix:/var/www/django/conf/sockets/$1.sock failed (111: Connection refused) while connecting to upstream, client: 82.15.29.187, server: servername, URL: &quot;/news/2009/jun/09/summer-fund-now-open-applications-continuing-stude/&quot;, upstream: &quot;fastcgi://unix:/var/www/django/conf/sockets/$1.sock:&quot;, host: &quot;servername&quot;, referrer: &quot;<a href="http://somewebsite.com/" target="_blank">http://somewebsite.com/</a>&quot;<br>

<br>
I&#39;ve switched file caching on now in django, so I&#39;m not getting any errors any more, but I need to understand what is causing those errors, for my own sanity if nothing else<br>
<br>
I can get any log information if needed, and perform any tests.  I think I&#39;ve got something setup slightly wrong, but I have no idea what it is.<br>
<br>
If anyone can shed any light on the topic I&#39;d be most grateful.<br>
<br>
V<br>
<br>
Posted at Nginx Forum: <a href="http://forum.nginx.org/read.php?2,3045,3045#msg-3045" target="_blank">http://forum.nginx.org/read.php?2,3045,3045#msg-3045</a><br>
<br>
<br>
</blockquote></div><br>