【问题标题】:Run a flask python app on apache server在 apache 服务器上运行烧瓶 python 应用程序
【发布时间】:2016-12-09 21:37:01
【问题描述】:

我正在运行一个 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.

【问题讨论】:

  • 你的服务器在运行吗?
  • 是的,我已经在我的问题中更新了它
  • 把这个添加到你的httpd文件下面 " MaxConnPerVhost 100 " 然后重启Apache看看它是否有效?
  • 检查 apache 错误日志,如果需要增加日志级别。
  • @error2007s 我收到语法错误&lt;IfModule takes one argument, Container for directives based on existance of specified modules

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


【解决方案1】:

请提前确保您在应用程序文件中可能有的任何 app.run() 调用都位于 if name == 'ma​​in': 块或移动到一个单独的文件。只要确保它没有被调用,因为如果我们将该应用程序部署到 mod_wsgi,这将始终启动一个我们不想要的本地 WSGI 服务器。

以上是http://flask.pocoo.org的摘录,好像发生在你身上。

【讨论】:

    【解决方案2】:

    好的,查看错误日志有助于我找出答案。

    因为我的错误是:

    (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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-16
      • 2022-01-06
      • 1970-01-01
      • 2021-11-04
      • 1970-01-01
      • 2014-04-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多