【发布时间】:2011-06-29 19:41:21
【问题描述】:
我有一个 django 应用程序,可以在 django 开发服务器下完美运行。现在我正在尝试使用 mod_wsgi 在 apache2.2 下运行它。
在我添加的 apache 的 httpd.conf 文件中:
<IfModule wsgi_module>
WSGIScriptAlias /index my_path_to_wsgi_modules/django.wsgi
</IfModule>
django.wsgi 模块包含 django 文档中解释的所有基本配置:http://docs.djangoproject.com/en/dev/howto/deployment/modwsgi/
不幸的是,当我运行服务器并尝试访问主页时,我获得了模板页面,但其中没有可变数据。服务器日志显示:
[Fri Feb 18 13:50:33 2011] [error] [client 127.0.0.1] File does not exist: /usr/local/apache2/htdocs/api, referer: http://127.0.0.1/example/
正如我之前所说的,奇怪的是相同的代码在 django 开发服务器下完美运行。我是编程网络应用程序的新手,请问有人可以帮忙吗?
我的 django.wsgi 文件如下所示:
导入操作系统 导入系统
从 os.path 导入 sep
basepath = '/home/example/WorkSpace/examplews/src'
sys.path.append(basepath)
sys.path.append('/home/example/WorkSpace/examplews/src/examplews')os.environ['DJANGO_SETTINGS_MODULE'] = 'examplews.settings'
导入 django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler()
还有我的 httpd.con 文件,像这样:
ServerRoot "/usr/local/apache2"
听 80
LoadModule wsgi_module modules/mod_wsgi.so
用户阿帕奇
组apacheServerAdmin 示例@domain.com
DocumentRoot "/usr/local/apache2/htdocs"
<Directory />
选项 FollowSymLinks
AllowOverride None
订单拒绝,允许
全部拒绝</Directory>
<Directory "/usr/local/apache2/htdocs">
选项索引 FollowSymLinksAllowOverride None
命令允许,拒绝
全部允许
</Directory>
<IfModule dir_module>
DirectoryIndex index.html index.php index.sh default.jsp</IfModule>
<FilesMatch "^\.ht">
订单允许,拒绝
全部拒绝
满足所有</FilesMatch>错误日志“日志/错误日志”
日志级别警告
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" 组合
LogFormat "%h %l %u %t \"%r\" %>s %b" 常见
<IfModule logio_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio</IfModule>
CustomLog "logs/access_log" common
</IfModule>
<IfModule alias_module></IfModule>
<IfModule cgid_module></IfModule>
<IfModule wsgi_module>
WSGIScriptAlias /main /home/example/WorkSpace/examplews/src/examplews/apache_conf/django.wsgi</IfModule><Directory "/home/example/WorkSpace/examplews/src/examplews/apache_conf">
订单允许,拒绝
全部允许</Directory>
DefaultType text/plain
<IfModule mime_module>
TypesConfig conf/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz</IfModule>
<IfModule ssl_module>
内置 SSLRandomSeed 启动
SSLRandomSeed 连接内置</IfModule>
【问题讨论】:
-
/usr/local/apache2/htdocs/api真的存在吗?也许 Apache 中的其他东西配置错误。 -
不,/usr/local/apache2/htdocs/api 它不存在。实际上它是一个虚拟 URL,应该通过 django urls.py 访问
-
请发布您的完整 Apache 配置和 wsgi 文件。
-
我已经在上面发布了我的 django.wsgi 和我的 httpd.conf。非常感谢!
标签: python django apache mod-wsgi django-urls