2015-02-10 64 views
0

我是Nginx和uWSGI的新成員。uWSGI和Nginx中的MyQSL連接502錯誤

我已更新我的index.py/var/www/app/目錄。而現在,當我嘗試運行http://127.0.0.1/cp.myhost.com我得到了502 Bad Gateway錯誤

這是Nginx的配置文件:

`

server { 

# Change this if you want to serve your application on another port 
listen 80; 

# Replace this with your domain name 
server_name cp.myhost.com; 

# You can use virtual directory like '/apps/' here, but remember that 
# this should match 'urls' defined in your web.py application file 
location/{ 
include uwsgi_params; 

# This should match the 'socket' entry in your uwsgi configuration 
#uwsgi_pass unix:///tmp/uwsgi_vhosts.sock; 
uwsgi_pass 127.0.0.1:8080; 

# This is the absolute path to the folder containing your application 
uwsgi_param UWSGI_CHDIR /var/www/apps; 

# This is actually not necessary for our simple application, 
# but you may need this in future 
uwsgi_param UWSGI_PYHOME /var/www/apps; 

# This is the name of your application file, minus the '.py' extension 
uwsgi_param UWSGI_SCRIPT index; 
} 
} 

`

,這是我的代碼at /var/www/app/index.py

import web 
import MySQLdb 
import datetime 

app = web.application(urls, globals()) 

urls = (
    '/', 'index' 
) 

class index: 
    def GET(self): 
     db = MySQLdb.connect(host="localhost", 
        user="root", 
         passwd="", 
         db="cw_api") 

     cur = db.cursor() 

     try: 
      cur.execute("SELECT MAX(sync_id) FROM settings_sync;")  
      db.commit() 
      print cur.fetchone()[0] 
     except: 
      db.rollback() 

     sql = "SELECT * FROM Table1 LEFT JOIN Table2 ON.... " 
     srtr = "<style>table, th, td {border: 1px solid black;}</style><table><tr><th>Name</th><th>Contact</th></tr>" 
    try: 
     # Execute the SQL command 
     cur.execute(sql) 
     # Fetch all the rows in a list of lists. 
     results = cur.fetchall() 
     for row in results:   
      srtr = srtr + "<tr><td>" + row[0] + "</td>" 
      srtr = srtr + "<td>" + row[1] + "</td>" 
      srtr = srtr + "</td></tr>" 

    except: 
     print "Error: unable to fecth data" 
    db.close() 

    srtr = srtr + "</table>" 
    return srtr 

if __name__ == "__main__": app.run() 

application = app.wsgifunc() 

我是新來的,所以請幫助我... 我認爲問題出在我的代碼中,但它在我的本地計算機上運行平穩。 我找不到哪裏是我的代碼錯誤...

我認爲錯誤是此代碼:

db = MySQLdb.connect(host="localhost", 
       user="root", 
        passwd="", 
        db="cw_api") 

cur = db.cursor() 

我試圖改變host價值爲127.0.0.1但沒有任何反應。

我對我的nginx/error.log有這樣的/var/log/uwsgi/app/vhost.log

libgcc_s.so.1 must be installed for pthread_cancel to work 
- DAMN ! worker 1 (pid: 18262) died, killed by signal 6 :(trying respawn ... 
- Respawned uWSGI worker 1 (new pid: 19584) 
- WSGI app 0 (mountpoint='cp.myhost.com|') ready in 0 seconds on interprete$ 
cp.myhost.com {address space usage: 94265344 bytes/89MB} {rss usage: 1175961$ 
libgcc_s.so.1 must be installed for pthread_cancel to work 
- DAMN ! worker 1 (pid: 19584) died, killed by signal 6 :(trying respawn ... 
- Respawned uWSGI worker 1 (new pid: 19597) 
libgcc_s.so.1 must be installed for pthread_cancel to work 
- DAMN ! worker 1 (pid: 19597) died, killed by signal 6 :(trying respawn ... 
- Respawned uWSGI worker 1 (new pid: 19633) 
libgcc_s.so.1 must be installed for pthread_cancel to work 
- DAMN ! worker 1 (pid: 19633) died, killed by signal 6 :(trying respawn ... 
- Respawned uWSGI worker 1 (new pid: 19638) 
libgcc_s.so.1 must be installed for pthread_cancel to work 
- DAMN ! worker 1 (pid: 19638) died, killed by signal 6 :(trying respawn ... 
- Respawned uWSGI worker 1 (new pid: 19677) 

我得到這個:

.. 20092#0: *5 upstream prematurely closed connection while reading response header from upstream, ...

+1

似乎你的Python代碼是兄弟肯。 – 2015-02-10 07:07:18

+0

我現在就看到它。這個問題是在我的代碼,但它運行在我的本地計算機..我想知道錯誤在哪裏 – gadss 2015-02-10 21:22:16

+0

你看到Web服務器日誌中的任何錯誤? – bmhkim 2015-02-10 21:45:29

回答