mod_wsgi中的Hello World

Pra*_*har 16 python apache mod-wsgi wsgi

在我尝试让我的烧瓶应用程序在Apache上运行后反复失败后,我mod_wsgi决定尝试运行hello world示例.这是我的 -

目录结构(我将apache默认更改/var/www~/public_html)

- public_html    
   - wsgi-scripts
      - test_wsgi.wsgi
   - test_wsgi
      - test_wsgi.wsgi
Run Code Online (Sandbox Code Playgroud)

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]
Run Code Online (Sandbox Code Playgroud)

VirtualHost配置文件(称为testwsgi) - 驻留在 /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>
Run Code Online (Sandbox Code Playgroud)

当我尝试localhost/wsgi使用浏览器时,我收到404 Not Found错误.我究竟做错了什么?这是我第一次尝试在生产服务器上部署应用程序.到目前为止,我采用了简单的方法来使用Google App Engine.我无法继续部署我的烧瓶应用程序,直到它启动并运行.非常感谢!

Mik*_*ton 12

您需要使用绝对路径,即不要使用~.这对我来说很好......

[mpenning@tsunami 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>
[mpenning@tsunami public_html]$
Run Code Online (Sandbox Code Playgroud)

首先我设置了一个主机名/etc/hosts,所以我可以确保我可以在查询中复用主机名...

[mpenning@tsunami public_html]$ grep wsgihost /etc/hosts
127.0.1.1       tsunami.foo.net  tsunami wsgihost
[mpenning@tsunami public_html]$
Run Code Online (Sandbox Code Playgroud)

重启apache,发出一个wget ...

[mpenning@tsunami 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â

[mpenning@tsunami public_html]$ cat index.html
Hello World![mpenning@tsunami public_html]$ #  <------
Run Code Online (Sandbox Code Playgroud)