2017-01-31 5 views
2

私はネットワークマシン上のポートに非常に単純なフラスコアプリを実行しようとしています。私の現在のサーバーのコードは次のようになります。特定のポートでmod_wsgiを使ってFlaskアプリを実行することはできますか?

from flask import Flask 
import json 
app = Flask(__name__) 

@app.route('/my_route') 
def my_route(): 
    return json.dumps({'data': 'this is an example'}) 

私のネットワーク上のマシンのIPが123.123.123.123だった、と私はポート5000に私のアプリを実行したいと言います。私はブラウザでナビゲートするか、単純なHTTPリクエストを123.123.123.123:5000/my_routeにしてJSONという応答を得たいと考えています。

私はmod_wsgi Flask documentationに追って失敗しました。

Listen 5000 
NameVirtualHost *:5000 
<VirtualHost *:5000> 
     ServerName gcr_app 

     WSGIDaemonProcess gcr_app user=apache threads=5 
     WSGIScriptAlias//var/www/gcr_app/gcr_app.wsgi 

     <Directory /var/www/gcr_app> 
       WSGIProcessGroup gcr_app 
       WSGIApplicationGroup %{GLOBAL} 
       Order deny,allow 
       Allow from all 
     </Directory> 
</VirtualHost> 

をしてhttpdサービスを再起動:私はこのようなディレクティブでhttpd.confを編集した後500 Internal Serverエラーが表示さになりました。

私はここで間違っていますか?その他の情報:

  • RHEL 6.7
  • のPython 3.4.4
  • フラスコ0.12

Apacheのバージョン:

$ /usr/sbin/httpd -v 
Server version: Apache/2.2.15 (Unix) 
Server built: Feb 4 2016 08:22:15 

私は提供することができ、他の有用な情報がありますなら、私を知ってみましょう。

エラーログ情報

[Mon Jan 30 17:55:22 2017] [error] [client x.x.x.x] (13)Permission denied: mod_wsgi (pid=2118): Unable to connect to WSGI daemon process 'gcr_app' on '/etc/httpd/logs/wsgi.2109.0.1.sock' after multiple attempts. 
[Mon Jan 30 17:55:26 2017] [error] [client x.x.x.x] (13)Permission denied: mod_wsgi (pid=2114): Unable to connect to WSGI daemon process 'gcr_app' on '/etc/httpd/logs/wsgi.2109.0.1.sock' after multiple attempts. 
[Mon Jan 30 17:55:27 2017] [error] [client x.x.x.x] (13)Permission denied: mod_wsgi (pid=2115): Unable to connect to WSGI daemon process 'gcr_app' on '/etc/httpd/logs/wsgi.2109.0.1.sock' after multiple attempts. 
[Mon Jan 30 17:55:46 2017] [error] [client x.x.x.x] (13)Permission denied: mod_wsgi (pid=2113): Unable to connect to WSGI daemon process 'gcr_app' on '/etc/httpd/logs/wsgi.2109.0.1.sock' after multiple attempts. 
[Mon Jan 30 17:57:48 2017] [error] [client x.x.x.x] File does not exist: /var/www/html/gcr_distance 
[Mon Jan 30 17:57:48 2017] [error] [client x.x.x.x] File does not exist: /var/www/html/favicon.ico, referer: http://x.x.x.x/my_route 
[Mon Jan 30 18:43:49 2017] [error] [client x.x.x.x] (13)Permission denied: mod_wsgi (pid=2116): Unable to connect to WSGI daemon process 'gcr_app' on '/etc/httpd/logs/wsgi.2109.0.1.sock' after multiple attempts. 

おかげ

+1

あなたは '/ var/log/httpd/*'に表示されているエラーを投稿するべきです –

+0

それらを見て、何か重要なものがあるかどうかを確認してください –

+0

Apache 2.2またはApache 2.4を実行していますか?あなたの設定は2.2で、RHEL 6と同じです。しかし、もしあなたがApache 2.4にアップグレードしたなら、パーミッションエラーを引き起こすかもしれない別の設定フォーマットがあります。 – FlipperPA

答えて

0
この質問についてコメントしてすべての人に感謝し

FlaskとPythonバージョンmod_wsgiを実行するために使用していたPythonバージョンに問題があることが判明しました。私はRHEL 6.7を使っているので、mod_wsgiがPython 2.7でインストールされていましたが、私はPython 3.4を使ってアプリケーションを書いていました。これは、mod_wsgiが私が使用していたモジュールのインポートに問題があることを意味していました。

これに加えて、Flaskアプリを適切にインポートしていませんでした。 、私はFlaskアプリケーションを実行することができた互換性のある2.7になるようにPythonコードの一部を変更し、私の.wsgiファイルを固定した後

from my_app import app as application 

import my_app as application 

の代わりに:私は私の.wsgiファイルでこれを持っていました私が望む港に

私のPython 3.4バージョンのpipFlaskアプリをPython 3.4で実行する場合にmod_wsgiをインストールすると、この回答が更新されます。

関連する問題