【问题标题】:How to solve permission errors when deploying flask app on apache using wsgi?使用wsgi在apache上部署flask app时如何解决权限错误?
【发布时间】:2017-04-01 11:20:01
【问题描述】:

我在使用 wsgi 在 apache2 上部署烧瓶应用程序时遇到问题。 Apache2 重新启动,好像它运行良好,但是当我尝试使用浏览器访问它时,我收到“403 Forbidden”错误。这是我的代码。

webroombooker.wsgi

#!/usr/bin/python

import sys
import logging

logging.basicConfig(stream=sys.stderr)

sys.path.insert(0,"/home/pi/Website/webroombooker.py")

from webroombooker import app as application

这是我的 Flask 应用程序和 wsgi 文件所在目录的目录树。

/home/pi/Website
├── hellotest.py
├── hellotest.pyc
├── index.html.en
├── index.html.en~orig.html
├── main.html
├── PoweredByMacOSX.gif
├── PoweredByMacOSXLarge.gif
├── templates
│       ├── profile.html
│       ├── registration2.html
│       ├── registration.html
│       ├── seleniumtemplate2.html
│       └── seleniumtemplatetime.html
├── Test
├── webroombooker.py
├── webroombooker.pyc
└── webroombooker.wsgi

这里是 apache 虚拟主机文件。

<VirtualHost *:80>
            ServerName localhost

            WSGIScriptAlias / /home/pi/Website/webroombooker.wsgi

            <Directory /home/pi/Website/webroombooker.py/>
                    Require all granted
            </Directory>
            ErrorLog ${APACHE_LOG_DIR}/error.log
            LogLevel warn
            CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

这里是相关的错误日志行 实际上它现在显示错误。

[Thu Nov 17 14:07:39.939432 2016] [authz_core:error] [pid 15949:tid          1972368432] [client ::1:55490] AH01630: client denied by server     configuration: /home/pi/Website/webroombooker.wsgi
[Thu Nov 17 14:07:40.260731 2016] [authz_core:error] [pid 15949:tid 1963979824] [client ::1:55490] AH01630: client denied by server configuration: /home/pi/Website/webroombooker.wsgi, referer: http://localhost/
[Thu Nov 17 14:07:43.506135 2016] [authz_core:error] [pid 15949:tid 1955591216] [client ::1:55490] AH01630: client denied by server configuration: /home/pi/Website/webroombooker.wsgi
[Thu Nov 17 14:07:43.702542 2016] [authz_core:error] [pid 15949:tid 1947202608] [client ::1:55490] AH01630: client denied by server configuration: /home/pi/Website/webroombooker.wsgi, referer: http://localhost/

我对此很陌生,所以我真的很感激。非常感谢您的帮助。

【问题讨论】:

  • 你能告诉我们apache日志文件的相关行吗?
  • 由于某种原因,当我请求站点时,apache 日志没有显示任何错误。
  • 实际上它现在显示错误。我来发一下

标签: python linux apache flask apache2


【解决方案1】:

这可能是您对 apache 正在访问的某些文件的 unix 权限的结果。 Apache 以用户 www-data 运行,其中文件可能归您的用户所有。尝试为相关文件运行 sudo chmod a+w &lt;filename&gt;,这可能是您的 wsgi 文件

【讨论】:

  • 试过了,我相信所有权限都设置正确。查看更改和执行权限设置为任何人。在网站目录中的每个文件上。
  • 您可以在问题中包含 /home/pi/Website/webroombooker.wsgi 吗?该错误似乎是在说内部的某些东西拒绝客户端访问所请求的任何资源。
  • 嘿!谢谢!我相信这就是问题的第一个代码块中的内容。我只是重命名了它。我的坏。
  • 太棒了!如果有帮助,介意投票并将我的答案标记为正确吗? :)
  • 嘿,你有没有机会投票赞成我的问题,有人只是反对,我不知道为什么。
猜你喜欢
  • 2011-04-11
  • 2021-06-23
  • 2021-04-29
  • 2015-11-21
  • 1970-01-01
  • 2014-09-09
  • 2011-02-08
  • 2013-05-03
  • 1970-01-01
相关资源
最近更新 更多