2012-08-29 9 views
16

mod_wsgiを使用して私のフラスコのアプリケーションをApache上で動かすことを私の探求で繰り返し失敗した後、私はhello world exampleを実行しようと決めました。ここで私が持っているものである -こんにちはWorld in mod_wsgi

ディレクトリ構造を

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

test_wsgi.wsgiファイル(私は、Apacheのデフォルト~/public_html/var/wwwを変更)

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] 

のVirtualHostの設定ファイル(と呼ばれる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

絶対パスを使用する必要があります。すなわち、~を使用しないでください。これは私が/etc/hostsにホスト名を設定するので、私は、私は、クエリで、ホスト名にマルチプレクサ・できることを確認できた

[[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]$ 

まず...私のため正常に動作します...

[[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]$ # <------