[英]Configure Python flask application with apache and mod_wsgi in linux
I have a linux apache 2.4.12 and mod_wsgi 4.5.2 (mod_wsgi.so installed into apache) under application account. 我在应用程序帐户下有一个linux apache 2.4.12和mod_wsgi 4.5.2(mod_wsgi.so安装到apache中)。 Apache runs under port 8050 under application account.
Apache在应用程序帐户下的端口8050下运行。 Following this link to test mod_wsgi working: http://modwsgi.readthedocs.org/en/develop/user-guides/quick-configuration-guide.html#wsgi-application-script-file and I entered my URL: http://mytest.mydomain.com:8050/myapp .
以下链接测试mod_wsgi的工作: http://modwsgi.readthedocs.org/en/develop/user-guides/quick-configuration-guide.html#wsgi-application-script-file和我进入我的网址: HTTP:/ /mytest.mydomain.com:8050/myapp 。 It displayed "Hello World", so it indicated my mod_wsgi installation working.
它显示“Hello World”,因此它表明我的mod_wsgi安装正常。 Next I tried to see if I can make flask application work.
接下来我试着看看我是否可以使烧瓶应用工作。
I created the simple hello.py file under /home/myuserId/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()
then I created a simple wsgi file as: 然后我创建了一个简单的wsgi文件:
import sys, os
sys.path.insert(0, "/home/myuserId/wsgi")
from hello import app as application
then I followed others suggestions including this http://flask.pocoo.org/docs/0.10/deploying/mod_wsgi/ to configure my apache http.conf file with virtualhost as: 然后我跟随其他建议,包括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>
I saved the httpd.conf file and restarted the apache w/o error. 我保存了httpd.conf文件并重新启动了apache w / o错误。 When I entered the URL in chrome: http://mytest.mydomain.com:8050/hello or http://mytest.mydomain.com:8050/hello_world , I got this error:
当我在chrome中输入网址: http : //mytest.mydomain.com : 8050 / hello或http://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.
My questions are: 我的问题是:
WSGIScriptAlias /hello /home/myuserId/wsgi/hello.wsgi
to mount hello application but not found either. WSGIScriptAlias /hello /home/myuserId/wsgi/hello.wsgi
来挂载hello应用程序但是找不到。 You aren't specifying ServerName directive with host name. 您没有使用主机名指定ServerName指令。 As a result it will not match that VirtualHost and will instead fallback to whatever the first VirtualHost was that it found in the Apache configuration files.
因此,它将与VirtualHost不匹配,而是将回退到它在Apache配置文件中找到的第一个VirtualHost。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.