【问题标题】:mod_wsgi forbidden error on CentOS 5.7CentOS 5.7 上的 mod_wsgi 禁止错误
【发布时间】:2012-03-02 02:06:58
【问题描述】:

我知道这个问题被问了数百万次,但我已经花了很多时间尝试在 CentOS 5.7 上配置 Apache 和 mod_wsgi,这对我来说是新的。在 Debian (Ubuntu) 上从来没有遇到过这种问题。

我在/etc/httpd/conf.d/ 目录中创建了wsgi.conf,包含以下几行:

LoadModule wsgi_module modules/mod_wsgi.so
WSGIPythonHome /var/xxx/env

/var/xxx/env 包含项目的虚拟环境。

然后我在/etc/httpd/conf.d/ssl.conf 中添加了以下几行(是的,我需要它用于 https,但我也尝试将其放入普通虚拟主机中)。

WSGIScriptAlias /suburl /var/xxx/yyy/hello.wsgi
<Location /suburl>
  Order deny,allow
  Allow from all
</Location>

hello.wsgi 包含

def application(environ, start_response):
       status = '200 OK'
       output = 'Hello World!'
       response_headers = [('Content-type', 'text/plain'),
              ('Content-Length', str(len(output)))]
       start_response(status, response_headers)
       return [output]

这是ls -l /var/xxx/的输出

 total 16
 drwxr-xr-x 5 apache apache 4096 Feb  9 05:14 env
 drwxr-xr-x 7 apache apache 4096 Feb  9 05:41 yyy

ls -l /var/xxx/yyy/的输出

total ...
...
-rwxr-xr-x 1 apache apache  238 Feb  9 05:19 hello.wsgi
...

ps -Af | grep httpd 显示

 root      8872     1  0 07:06 ?        00:00:00 /usr/sbin/httpd
 apache    8874  8872  0 07:06 ?        00:00:00 /usr/sbin/httpd
 apache    8875  8872  0 07:06 ?        00:00:00 /usr/sbin/httpd
 apache    8876  8872  0 07:06 ?        00:00:00 /usr/sbin/httpd
 apache    8877  8872  0 07:06 ?        00:00:00 /usr/sbin/httpd
 apache    8878  8872  0 07:06 ?        00:00:00 /usr/sbin/httpd
 apache    8879  8872  0 07:06 ?        00:00:00 /usr/sbin/httpd
 apache    8880  8872  0 07:06 ?        00:00:00 /usr/sbin/httpd
 apache    8881  8872  0 07:06 ?        00:00:00 /usr/sbin/httpd
 fedor    10609  4716  0 07:16 pts/1    00:00:00 grep httpd

/var/log/httpd/ssl_error_log 充满了如下几行

[Thu Feb 09 07:06:47 2012] [error] [client 127.0.0.1] (13)Permission denied: access to /suburl denied

但它通过调用 sudo /usr/sbin/httpd hello.wsgi 启动 Apache 开始工作,即使 ps -Af | grep httpd 显示非常相似的行:

root     11442     1  3 07:21 ?        00:00:00 /usr/sbin/httpd
apache   11443 11442  0 07:21 ?        00:00:00 /usr/sbin/httpd
apache   11444 11442  0 07:21 ?        00:00:00 /usr/sbin/httpd
apache   11445 11442  0 07:21 ?        00:00:00 /usr/sbin/httpd
apache   11446 11442  0 07:21 ?        00:00:00 /usr/sbin/httpd
apache   11447 11442  0 07:21 ?        00:00:00 /usr/sbin/httpd
apache   11448 11442  0 07:21 ?        00:00:00 /usr/sbin/httpd
apache   11449 11442  0 07:21 ?        00:00:00 /usr/sbin/httpd
apache   11450 11442  0 07:21 ?        00:00:00 /usr/sbin/httpd
fedor    11453  4716  0 07:21 pts/1    00:00:00 grep httpd

任何可能导致问题的想法以及我还需要检查什么?

【问题讨论】:

    标签: python apache centos mod-wsgi wsgi


    【解决方案1】:

    在文件和目录上设置适当的 SELinux 文件上下文。有关详细信息,请参阅 httpd_selinux(8) 手册页。

    【讨论】:

    • 感谢您的帮助。在我完成sudo chcon -t httpd_sys_script_exec_t /var/xxx/yyy/hello.wsgi 之后,脚本开始工作。但我仍然在导入一些模块(例如 cStringIO)时遇到问题。有什么想法可能导致这种情况吗?我尝试对整个 env 目录执行 chcon,但似乎没有帮助。
    • 这个 selinux 技巧对于那些使用 CentOS 的人来说非常有用。我在 6.1 并关注the famous video tutorial without luck。我使用echo 0&gt;/selinux/enforcing 成功禁用了selinux
    猜你喜欢
    • 2014-05-24
    • 2016-07-12
    • 2014-02-03
    • 2012-04-05
    • 2013-07-19
    • 1970-01-01
    • 1970-01-01
    • 2014-09-20
    • 2018-07-12
    相关资源
    最近更新 更多