2012-08-29 196 views
16

在我試圖讓我的燒瓶應用程序在Apache上運行使用mod_wsgi反覆失敗後,我決定嘗試運行hello world example。以下是我有 -Hello World在mod_wsgi

目錄結構(我改變了apache默認/var/www~/public_html

- public_html  
    - wsgi-scripts 
     - test_wsgi.wsgi 
    - test_wsgi 
     - test_wsgi.wsgi 

test_wsgi.wsgi文件

def application(environ, start_response): 
    status = '200 OK' 
    output = 'Hello World!' 

    response_headers = [('Content-type', 'text/plain'), 
         ('Content-Length', str(len(output)))] 

    start_response(status, response_headers) 

    return [output] 

虛擬主機配置文件(稱爲testwsgi) - 此駐留in /etc/apache2/sites-enabled/

<VirtualHost *:80> 
    DocumentRoot ~/public_html/test_wsgi 

    <Directory ~/public_html/test_wsgi> 
     Order allow,deny 
     Allow from all 
    </Directory> 

    WSGIScriptAlias /wsgi ~/public_html/wsgi-scripts/test_wsgi.wsgi 

    <Directory ~/public_html/wsgi-scripts> 
     Order allow,deny 
     Allow from all 
    </Directory> 
</VirtualHost> 

當我嘗試在瀏覽器上訪問localhost/wsgi時,出現404 Not Found錯誤。我究竟做錯了什麼?這是我第一次嘗試在生產服務器上部署應用程序。到現在爲止,我使用了Google App Engine的簡單方法。我無法繼續部署我的燒瓶應用程序,直到它啓動並運行。非常感謝!

回答

12

您需要使用絕對路徑,即不要使用~。這工作得很好,我...

[[email protected] public_html]$ sudo cat /etc/apache2/sites-available/wsgi_test 
<VirtualHost *:80> 
    ServerName wsgihost 
    DocumentRoot /home/mpenning/public_html 
    WSGIScriptAlias//home/mpenning/public_html/test.wsgi 
</VirtualHost> 
[[email protected] public_html]$ 

首先,我建立了一個主機名/etc/hosts,所以我可以保證,我可以在查詢的主機名混流...

[[email protected] public_html]$ grep wsgihost /etc/hosts 
127.0.1.1  tsunami.foo.net tsunami wsgihost 
[[email protected] public_html]$ 

重新啓動Apache ,併發出wget ...

[[email protected] public_html]$ wget http://wsgihost/ 
--2012-08-29 05:50:26-- http://wsgihost/ 
Resolving wsgihost... 127.0.1.1 
Connecting to wsgihost|127.0.1.1|:80... connected. 
HTTP request sent, awaiting response... 200 OK 
Length: 12 [text/plain] 
Saving to: âindex.html.3â 

100%[======================================>] 12   --.-K/s in 0s 

2012-08-29 05:50:26 (1.48 MB/s) - âindex.html.3â 

[[email protected] public_html]$ cat index.html 
Hello World![[email protected] public_html]$ # <------