我知道這個問題被問了數百萬次,但我已經花了很多時間嘗試在CentOS 5.7上配置Apache和mod_wsgi,這對我來說是新的。在Debian(Ubuntu)上從未遇到這種問題。mod_wsgi在CentOS 5.7上禁止的錯誤
我在/etc/httpd/conf.d/
目錄中創建wsgi.conf
,containting下面幾行:
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開始工作,儘管ps -Af | grep httpd
節目非常相似行啓動Apache:
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
任何想法可能會導致問題,我還有什麼要檢查?
謝謝你的幫助。在完成'sudo chcon -t httpd_sys_script_exec_t/var/xxx/yyy/hello.wsgi'後,腳本開始工作。但我仍然有問題導入一些模塊(例如cStringIO)。任何想法可能會導致這種情況?我試圖爲整個env目錄執行chcon,但似乎沒有幫助。 – Fedor 2012-02-13 11:09:13
這個selinux提示對CentOS上的人來說是金色的。我在6.1,並且[着名的視頻教程沒有運氣](https://code.google.com/p/modwsgi/wiki/WhereToGetHelp?tm=6)。我成功地通過'echo 0>/selinux/enforcing'禁用了selinux – hamx0r 2013-07-10 21:52:39