在apache服务器上运行一个烧瓶python应用程序

时间:2016-08-04 00:55:15

标签: python apache amazon-web-services amazon-ec2 flask

我正在运行一个Amazon EC2微型实例,我想使用Flask从它运行一个python应用程序。

这是我的app.py文件,我正在进行简单的文件上传(它在localhost:5000上正常工作):

from flask import Flask
app = Flask(__name__)

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

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

这是我的名为adapter.wsgi的文件,用于将其连接到apache:

import sys
sys.path.insert(0, '/var/www/html/lumos')

from app import app as application

最后,在我的httpd.conf文件中,我完成了以下操作:

<VirtualHost *>
ServerName http://lumos.website.me
DocumentRoot /var/www/html/lumos

WSGIDaemonProcess lumos threads=5
WSGIScriptAlias / /var/www/html/lumos/adapter.wsgi
        <Directory "/var/www/html/lumos">
                WSGIProcessGroup lumos
                WSGIApplicationGroup %{GLOBAL}
                Order deny,allow
                Allow from all
        </Directory>
</VirtualHost>

然后当我重新启动apache服务器并转到http://lumos.website.me/时,我得到的只是503:

Service Temporarily Unavailable

The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.

Apache/2.2.31 (Amazon) Server at lumos.website.me Port 80

关于如何让烧瓶应用程序在Apache服务器上运行的任何想法?

注意:我的服务器正在运行。

更新

这是我的错误日志文件

[Thu Aug 04 01:34:09 2016] [notice] caught SIGTERM, shutting down
[Thu Aug 04 01:34:09 2016] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Thu Aug 04 01:34:09 2016] [notice] Digest: generating secret for digest authentication ...
[Thu Aug 04 01:34:09 2016] [notice] Digest: done
[Thu Aug 04 01:34:10 2016] [notice] Apache/2.2.31 (Unix) DAV/2 PHP/5.3.29 mod_wsgi/3.2 Python/2.6.9 configured -- resuming normal operations
[Thu Aug 04 01:34:14 2016] [error] [client 72.219.147.5] (13)Permission denied: mod_wsgi (pid=30315): Unable to connect to WSGI daemon process 'lumos' on '/etc/httpd/logs/wsgi.30311.0.1.sock' after multiple attempts.
[Thu Aug 04 01:34:14 2016] [error] [client 72.219.147.5] (13)Permission denied: mod_wsgi (pid=30316): Unable to connect to WSGI daemon process 'lumos' on '/etc/httpd/logs/wsgi.30311.0.1.sock' after multiple attempts., referer: http://lumos.website.me/
[Thu Aug 04 01:34:15 2016] [error] [client 72.219.147.5] (13)Permission denied: mod_wsgi (pid=30317): Unable to connect to WSGI daemon process 'lumos' on '/etc/httpd/logs/wsgi.30311.0.1.sock' after multiple attempts.

2 个答案:

答案 0 :(得分:1)

  

请事先确保您的应用程序文件中的任何app.run()调用都位于if 名称 ==&#39; main & #39 ;:阻止或移动到单独的文件。只是确保它没有被调用,因为如果我们将该应用程序部署到mod_wsgi,这将始终启动我们不想要的本地WSGI服务器。

以上摘自http://flask.pocoo.org,似乎与您同在。

答案 1 :(得分:0)

好的,所以看错误日志帮我弄清楚了答案。

由于我的错误是:

(13)Permission denied: mod_wsgi (pid=30315): Unable to connect to WSGI daemon process 'lumos' on '/etc/httpd/logs/wsgi.30311.0.1.sock' after multiple attempts.

我在httpd.conf文件中添加了此WSGISocketPrefix /var/run/wsgi并重新启动了apache。

对于将来可能遇到与我相同问题的其他人,以下是对我的错误的更详细解释:

https://code.google.com/archive/p/modwsgi/wikis/ConfigurationIssues.wiki#Location_Of_UNIX_Sockets