NameError: global name 'start_responses' is not defined after modifying my myapp.wsgi file

NameError: global name 'start_responses' is not defined after modifying my myapp.wsgi file

之前我得到的 Apache is 运行 页面。然后我修改了

/etc/apache2/sites-enabled/000-default.conf

我在顶部添加,在 VirtualHost 标签之外

ServerName 127.0.0.1 

然后在结束标签之前,我添加了这个:

WSGIScriptAlias / /var/www/html/myapp.wsgi
</VirtualHost>

这是我的 myapp.wsgi 文件

def application(environ, start_response):
status = '200 OK'
output = 'Hello World!'

response_headers= [('Content-type', 'text/plain'),('Content-Length',
                     str(len(output)))]
start_responses(status,response_headers)

现在我在访问我的 public IP 地址时收到 500 内部服务器错误。

这是我的error.log

    [Sat Dec 10 16:05:36.698052 2016] [:error] [pid 12468:tid 140408204646144] [client 108.49.103.204:56866]   File "/var/www/html/myapp.wsgi", line 7, in application, referer: http://35.164.22.192/
[Sat Dec 10 16:05:36.698079 2016] [:error] [pid 12468:tid 140408204646144] [client 108.49.103.204:56866]     start_responses(status,response_headers), referer: http://35.164.22.192/
[Sat Dec 10 16:05:36.698096 2016] [:error] [pid 12468:tid 140408204646144] [client 108.49.103.204:56866] NameError: global name 'start_responses' is not defined, referer: http://35.164.22.192/

如错误所示,您错误地命名了正在调用的函数。 application 的参数是 start_response,不是 start_responses

此外,ServerName 绝不应该是 Apache 配置中的 IP 地址。大概你只有一个 VirtualHost 定义,因为在那种情况下它并不重要,因为什么时候出错,或者 Apache 不能正确匹配虚拟主机,它总是会在第一个 [=14] 处理你的请求=] 无论如何。