2012-08-29 191 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]$ # <------