2014-02-22 50 views
1

首先讓我說我是系統工程師,但我正在學習WebDev/DevOps材料,重點關注Python。因此,我正在將我的站點從WordPress(基於PHP)移動到Mezzanine(基於Python)。爲了從一個VPS運行多個站點,我使用Gunicorn設置VirtualEnv,並在前面設置Nginx。由於我的日常工作是作爲系統工程師,而且我使用RHEL服務器,CentOS 6是我目前選擇的虛擬主機平臺。以下是我現在有一個CentOS 6.5服務器上:Gunicorn網站未啓動?

***INSTALL PYTHON 3.3.4, PIP, VIRTUALENV*** 
yum groupinstall -y development 
yum install -y zlib-dev openssl-devel sqlite-devel bzip2-devel xz-libs 
wget http://www.python.org/ftp/python/3.3.4/Python-3.3.4.tar.xz 
xz -d Python-3.3.4.tar.xz 
tar -xvf Python-3.3.4.tar && cd Python-3.3.4 
./configure 
make && make altinstall 
wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-2.2.tar.gz 
tar -xvf setuptools-2.2.tar.gz && cd setuptools-2.2 
python3.3 setup.py install 
curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python3.3 - 
pip install virtualenv 

***SETUP SITES & GUNICORN*** 
rm -rf /root/Python* 
rm -rf /root/setuptools* 
mkdir /sites && mkdir /sites/sitename && mkdir /sites/sitename/app && cd /sites/sitename 
virtualenv sitename_venv 
source sitename_venv/bin/activate 
pip install gunicorn 
deactivate 

***WSGI*** 
cd /sites/sitename && vi wsgi.py 
source sitename_venv/bin/activate 
source sitename_venv/bin/activate 
gunicorn -b 0.0.0.0:8081 --workers=5 wsgi:app 

最後一節(WSGI)是測試出Gunicorn,並wsgi.py看起來是這樣的:

def app(environ, start_response): 
    """Simplest possible application object""" 
    data = 'Hello, World!\n' 
    status = '200 OK' 
    response_headers = [ 
     ('Content-type','text/plain'), 
     ('Content-Length', str(len(data))) 
    ] 
    start_response(status, response_headers) 
    return iter([data]) 

所以,當我開始現場,我看到:

(sitename_venv)[[email protected] sitename]# gunicorn -b 0.0.0.0:8081 --workers=5 wsgi:app 
2014-02-22 13:13:07 [36417] [INFO] Starting gunicorn 18.0 
2014-02-22 13:13:07 [36417] [INFO] Listening at: http://0.0.0.0:8081 (36417) 
2014-02-22 13:13:07 [36417] [INFO] Using worker: sync 
2014-02-22 13:13:07 [36420] [INFO] Booting worker with pid: 36420 
2014-02-22 13:13:07 [36421] [INFO] Booting worker with pid: 36421 
2014-02-22 13:13:07 [36422] [INFO] Booting worker with pid: 36422 
2014-02-22 13:13:07 [36423] [INFO] Booting worker with pid: 36423 
2014-02-22 13:13:07 [36424] [INFO] Booting worker with pid: 36424 

因此,網站應該是在運行,但是當我瀏覽到它(IP:8081 - 來自同一網絡,因爲這是一個本地虛擬機,而不是我的VPS尚)我只是「網頁不可用」。如果我停止Gunicorn,我會得到「Chrome無法連接......等等,等等」,所以我知道Gunicorn正在響應我的http請求。我不知道的是,爲什麼我看不到wsgi.py應該顯示什麼?有任何想法嗎?

Nginx尚未混合,所以它沒有配置。我一般對virtualenv和python還是比較陌生的,所以如果我的wsgi.py文件有問題,我不會感到驚訝。

謝謝!

EDIT1:

[[email protected] ~]# curl -v http://0:8081 
* About to connect() to 0 port 8081 (#0) 
* Trying 0.0.0.0... connected 
* Connected to 0 (0.0.0.0) port 8081 (#0) 
> GET/HTTP/1.1 
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2 
> Host: 0:8081 
> Accept: */* 
> 
< HTTP/1.1 200 OK 
< Server: gunicorn/18.0 
< Date: Sat, 22 Feb 2014 18:26:24 GMT 
< Connection: close 
< Content-type: text/plain 
< Content-Length: 14 
< 
* transfer closed with 14 bytes remaining to read 
* Closing connection #0 
curl: (18) transfer closed with 14 bytes remaining to read 
+0

東西在Gunicorn錯誤日誌之前對其進行編碼,如果有任何? 'curl -v http:// 0:8081'的輸出是什麼? – Messa

+0

OP中的@Messa EDIT1顯示了輸出。似乎它的工作,但wsgi.py沒有顯示任何東西。我對Gunicorn的日誌不太確定,因爲我對它很陌生。我沒有看到/ var/logs/*中的Gunicorn日誌和/ var/logs/messages中的任何內容。 – dhorn

回答

0

數據必須在Python 3二進制,所以返回

return iter([data.encode()])