【发布时间】:2016-12-28 05:56:08
【问题描述】:
操作系统:寡妇 2012r2
网络服务器:apache 2.4.23 (32bit)
蟒蛇:2.7.12
网络框架:web.py 0.38
mod_wsgi: mod_wsgi-4.4.23+ap24vc9-cp27-cp27m-win32
我给apache服务器系统权限,所以可以排除权限原因。
这整个过程是:Http-> Apache 2.4->mod_wsgi->web.py
wsgi.conf:
WSGIScriptAlias / "C:/Apache24/htdocs/test.py/"
Alias /static "C:/Apache24/htdocs/static/"
AddType text/html .py
<Directory "C:/Apache24/htdocs/">
Require all denied
Require all granted
</Directory>
================================================ ==
test.py:
coding:utf-8
import web
urls = (
'/.*', 'hello',
)
class hello:
def GET(self):
return "Hello, world."
app = web.application(urls, globals(), autoreload=False)
application = app.wsgifunc()
================================================ ==
然后,它起作用了!我打开IE,输入url:localhost:80,页面显示:Hello, world.
基于以上,我修改了wsgi.conf的代码:
================================================ ==
WSGIScriptAlias / "C:/Apache24/htdocs/code.py/"
Alias /static "C:/Apache24/htdocs/static/"
AddType text/html .py
<Directory "C:/Apache24/htdocs/">
Require all denied
Require all granted
</Directory>
================================================ ==
还有code.py:
coding: utf-8
import web
from config.url import urls
app = web.application(urls, globals())
application = app.wsgifunc()
================================================ ==
那么apache还是可以的,
但 error.log 显示:“目标 WSGI 脚本 'C:/Apache24/htdocs/code.py' 无法作为 Python 模块加载。”
而网址:localhost:80 无法使用,显示:“500 Internal Server Error”
谁能告诉我如何解决这个问题?非常感谢。
错误日志:
[Thu Aug 25 02:05:43.687446 2016] [wsgi:error] [pid 3780:tid 1248] [client 192.168.1.107:61159] mod_wsgi (pid=3780): Target WSGI script 'C:/Apache24/htdocs/code.py' cannot be loaded as Python module.
[Thu Aug 25 02:05:43.687446 2016] [wsgi:error] [pid 3780:tid 1248] [client 192.168.1.107:61159] mod_wsgi (pid=3780): Exception occurred processing WSGI script 'C:/Apache24/htdocs/code.py'.
[Thu Aug 25 02:05:43.687446 2016] [wsgi:error] [pid 3780:tid 1248] [client 192.168.1.107:61159] Traceback (most recent call last):
[Thu Aug 25 02:05:43.687446 2016] [wsgi:error] [pid 3780:tid 1248] [client 192.168.1.107:61159] File "C:/Apache24/htdocs/code.py", line 5, in <module>
[Thu Aug 25 02:05:43.687446 2016] [wsgi:error] [pid 3780:tid 1248] [client 192.168.1.107:61159] from config.url import urls
[Thu Aug 25 02:05:43.687446 2016] [wsgi:error] [pid 3780:tid 1248] [client 192.168.1.107:61159] ImportError: No module named config.url
[Thu Aug 25 02:05:43.859495 2016] [wsgi:error] [pid 3780:tid 1248] [client 192.168.1.107:61160] mod_wsgi (pid=3780): Target WSGI script 'C:/Apache24/htdocs/code.py' cannot be loaded as Python module., referer: 192.168.1.146
[Thu Aug 25 02:05:43.859495 2016] [wsgi:error] [pid 3780:tid 1248] [client 192.168.1.107:61160] mod_wsgi (pid=3780): Exception occurred processing WSGI script 'C:/Apache24/htdocs/code.py'., referer: 192.168.1.146
[Thu Aug 25 02:05:43.859495 2016] [wsgi:error] [pid 3780:tid 1248] [client 192.168.1.107:61160] Traceback (most recent call last):, referer: 192.168.1.146
[Thu Aug 25 02:05:43.859495 2016] [wsgi:error] [pid 3780:tid 1248] [client 192.168.1.107:61160] File "C:/Apache24/htdocs/code.py", line 5, in <module>, referer: 192.168.1.146
[Thu Aug 25 02:05:43.859495 2016] [wsgi:error] [pid 3780:tid 1248] [client 192.168.1.107:61160] from config.url import urls, referer: 192.168.1.146
[Thu Aug 25 02:05:43.859495 2016] [wsgi:error] [pid 3780:tid 1248] [client 192.168.1.107:61160] ImportError: No module named config.url, referer: 192.168.1.146
【问题讨论】:
-
能否正确格式化?
-
在 Apache 错误日志中的那一行之后,应该有 Python 堆栈跟踪和异常详细信息。那是什么?一开始在 Apache 配置中放置斜杠的地方错了,但让我们先看看错误回溯,因为斜杠可能是一个单独的问题。