可以在特定端口上运行带有mod_wsgi的Flask应用程序吗?

时间:2017-01-31 20:25:26

标签: python apache flask

我试图在网络机器上的端口上运行一个非常简单的烧瓶应用程序。我当前的服务器代码如下所示:

123.123.123.123

说我网络上的机器的IP是5000,我想在端口HTTP上运行我的应用程序。我希望能够在浏览器中导航或向123.123.123.123:5000/my_route发出简单的JSON请求并获得500 Internal Server响应。

我试图关注mod_wsgi Flask documentation但未成功。在使用如下指令编辑httpd.conf后,我收到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

并重新启动$ /usr/sbin/httpd -v Server version: Apache/2.2.15 (Unix) Server built: Feb 4 2016 08:22:15 服务。

我在这里做错了什么?其他信息:

  • RHEL 6.7
  • Python 3.4.4
  • 烧瓶0.12

Apache版本:

[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.

如果我能提供其他有用的信息,请告诉我。

错误日志信息

import random
unit = ["", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"]
teen = ["", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"]
tenth = ["", "Ten", "Twenty", "Thirty", "Fourty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"]
hundreth = ["", "One Hundred", "Two Hundred", "Three Hundred", "Four Hundred", "Five Hundred", "Six Hundred", "Seven Hundred", "Eight Hundred", "Nine Hundred"]
thousandth = ["", "One Thousand", "Two Thousand", "Three Thousand", "Four Thousand", "Five Thousand", "Six Thousand", "Seven Thousand", "Eight Thousand", "Nine Thousand"]
a = 11
while a>0:
  a = a - 1
  thenumber = str(random.randint(1000,9999))
  teen_check = (10 < int(thenumber[2:4]) < 20)
  if not teen_check:
    print(thousandth[int(thenumber[0])], hundreth[int(thenumber[1])], "and", tenth[int(thenumber[2])], unit[int(thenumber[3])])
    answer = input("What is this number?: ")
  else:
    print(thousandth[int(thenumber[0])], hundreth[int(thenumber[1])], "and", teen[int(thenumber[3])])
    answer = input("What is this number?: ")
  if answer == thenumber:
      print("Correct!")
  else:
    print("That is incorrect, unlucky")

由于

1 个答案:

答案 0 :(得分:0)

感谢所有评论此问题的人。事实证明,我在运行Flask时使用的Python版本和mod_wsgi的Python版本存在问题。由于我使用的是RHEL 6.7,mod_wsgi已经安装了Python 2.7,而我使用Python 3.4编写了我的应用程序。这意味着mod_wsgi无法导入我正在使用的模块。

除此之外,我还没有正确导入我的Flask应用。我在我的.wsgi文件中有这个:

import my_app as application

而不是:

from my_app import app as application

将一些Python代码更改为2.7兼容并修复我的.wsgi文件后,我能够在我想要的端口上运行Flask应用程序。

如果使用我的Python 3.4版本的mod_wsgi安装pip来运行使用Python 3.4的Flask应用程序,我将更新此答案。