簡體   English   中英

在linux中使用apache和mod_wsgi配置Python燒瓶應用程序

[英]Configure Python flask application with apache and mod_wsgi in linux

我在應用程序帳戶下有一個linux apache 2.4.12和mod_wsgi 4.5.2(mod_wsgi.so安裝到apache中)。 Apache在應用程序帳戶下的端口8050下運行。 以下鏈接測試mod_wsgi的工作: http://modwsgi.readthedocs.org/en/develop/user-guides/quick-configuration-guide.html#wsgi-application-script-file和我進入我的網址: HTTP:/ /mytest.mydomain.com:8050/myapp 它顯示“Hello World”,因此它表明我的mod_wsgi安裝正常。 接下來我試着看看我是否可以使燒瓶應用工作。

我在/ home / myuserId / wsgi下創建了簡單的hello.py文件:

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
   return 'Hello World!'

if __name__ == '__main__':
   app.run()

然后我創建了一個簡單的wsgi文件:

import sys, os
sys.path.insert(0, "/home/myuserId/wsgi")

from hello import app as application

然后我跟隨其他建議,包括http://flask.pocoo.org/docs/0.10/deploying/mod_wsgi/ ,用virtualhost配置我的apache http.conf文件:

<VirtualHost *:8050>

  # ServerName www.example.com

  WSGIDaemonProcess hello user=appuser group=appuser threads=5
  WSGIScriptAlias / /home/myuserId/wsgi/hello.wsgi

 <Directory /home/myuserId/wsgi>
    WSGIProcessGroup hello
    WSGIApplicationGroup %{GLOBAL}
    Require all granted
    Options +ExecCGI
    AddHandler wsgi-script .wsgi
 </Directory>
</VirtualHost>

我保存了httpd.conf文件並重新啟動了apache w / o錯誤。 當我在chrome中輸入網址: http//mytest.mydomain.com8050 / hellohttp://mytest.mydomain.com:8050/hello_world時 ,我收到此錯誤:

**Not Found**

The requested URL /hello was not found on this server.
Apache/2.4.12 (Unix) mod_wsgi/4.5.2 Python/2.7.9 Server at mytest.mydomain.com port 8050. 

我的問題是:

  1. 我的配置錯了嗎?
  2. 上面的hello flask應用程序使用的URL是什么?
  3. 嘗試使用WSGIScriptAlias /hello /home/myuserId/wsgi/hello.wsgi來掛載hello應用程序但是找不到。
  4. 對於燒瓶應用程序,為什么conf文件必須在VirtualHost中配置應用程序?

您沒有使用主機名指定ServerName指令。 因此,它將與VirtualHost不匹配,而是將回退到它在Apache配置文件中找到的第一個VirtualHost。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM