2014-07-21 60 views
2

我今天安裝了一個新的CentOS 7 x86_64 LAMP服務器。Apache/httpd/var/www/html/.cgi腳本丟500內部服務器錯誤

我在c中編譯了一個簡單的CGI腳本,我將其命名爲test.cgi,並且爲.cgi腳本啓用了AddHandler。然而,每次我嘗試從/ var/www/html目錄加載/test.cgi頁面時,任何簡單的.cgi腳本都會給我一個500內部服務器錯誤頁面。

我測試了腳本在/ var/www/cgi-bin目錄下工作正常。 我的服務器正在運行selinux,而apache/httpd正在使用suEXEC。

編輯:也沒有創建任何額外的用戶燈安裝後,所以在這裏我使用root來做所有的事情。不過,我試圖解決給Apache的用戶/ var/www/html目錄所有權,這並沒有修復悲傷。

這裏的錯誤日誌,你可以看到它給了我一個 '權限被拒絕' 的錯誤:

[Mon Jul 21 15:28:14.336626 2014] [core:notice] [pid 22704] SELinux policy enabled; httpd running as context system_u:system_r:httpd_t:s0 
[Mon Jul 21 15:28:14.339766 2014] [suexec:notice] [pid 22704] AH: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec) 
[Mon Jul 21 15:28:14.495631 2014] [auth_digest:notice] [pid 22704] AH01757: generating secret for digest authentication ... 
[Mon Jul 21 15:28:14.498690 2014] [lbmethod_heartbeat:notice] [pid 22704] AH02282: No slotmem from mod_heartmonitor 
[Mon Jul 21 15:28:14.765072 2014] [mpm_prefork:notice] [pid 22704] AH00163: Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips PHP/5.4.16 configured -- resuming normal operations 
[Mon Jul 21 15:28:14.765186 2014] [core:notice] [pid 22704] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND' 
[Mon Jul 21 15:28:16.027553 2014] [cgi:error] [pid 22706] [client 192.168.0.68:52930] AH01215: (13)Permission denied: exec of '/var/www/html/index.cgi' failed 
[Mon Jul 21 15:28:16.030595 2014] [cgi:error] [pid 22706] [client 192.168.0.68:52930] End of script output before headers: index.cgi 
[Mon Jul 21 15:45:01.586229 2014] [mpm_prefork:notice] [pid 22704] AH00170: caught SIGWINCH, shutting down gracefully 

這是我的/ var/www/html等Apache的配置:

<Directory "/var/www/html"> 
    #                                             
    # Possible values for the Options directive are "None", "All",                             
    # or any combination of:                                       
    # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews                          
    #                                             
    # Note that "MultiViews" must be named *explicitly* --- "Options All"                            
    # doesn't give it to you.                                       
    #                                             
    # The Options directive is both complicated and important. Please see                           
    # http://httpd.apache.org/docs/2.4/mod/core.html#options                               
    # for more information.                                       
    #                                             
    Options ExecCGI FollowSymLinks 

    #                                             
    # AllowOverride controls what directives may be placed in .htaccess files.                          
    # It can be "All", "None", or any combination of the keywords:                             
    # Options FileInfo AuthConfig Limit                                    
    #                                             
    AllowOverride All 

    #                                             
    # Controls who can get stuff from this server.                                 
    #                                             
    Require all granted 
</Directory> 

而且我當然激活CGI使用:AddHandler cgi-script .cgi .pl

這是我簡單test1.c文件:

#include <stdio.h> 

int main(void) { 
    puts("Content-Type: text/html; charset=ISO-8859-1\n"); 
    fputs("Hello, World!", stdout); 

    return 0; 
} 

輸出是正確:Content-Type: text/html; charset=ISO-8859-1\n\nHello, World!

而且我用gcc編譯它,然後把它的權限777 test.cgi 你知道什麼,我需要做的解決這一問題?

由於提前, Zorgatone

+0

我與Centos 7上的CGI腳本有同樣的問題。我正在嘗試安裝Bugzilla。我已經嘗試了所有不同的權限,包括刪除寫入權限並將所有者切換到apache.apache,但都沒有效果。 –

+0

500錯誤非常普遍...檢查日誌 – user83039

回答

0

我剛剛解決了重新安裝服務器,並做一遍所有,禁用SELinux和iptables的,因爲我已經有一個外部防火牆。

由於任何人誰幫我出;)

1

我不知道這對你是一個可行的解決方案,但我得到了它改變了SELinux,以寬容的工作。以下是您感興趣的步驟。

vi /etc/selinux/config 

更改以下行:

SELINUX=enforcing 

到:

SELINUX=permissive 
0

這很可能是一個SELinux的問題(其中湯姆·斯威尼answer提供了一個解決方案,使用許可SELinux和自己的接受answer您表示完全禁用SELinux) 。另一種方法是爲您的CGI文件配置適當的SELinux類型(以及可能的其他策略更改)。


要開始了,安裝的SELinux策略管理工具(如果尚未完成):

sudo yum install policycoreutils-python 

假設你想允許在您的/var/www/html目錄中的所有基於CGI的文件,你可以使用以下命令將httpd_sys_script_exec_t背景下適用於當前和未來的CGI文件:

sudo semanage fcontext -a -t httpd_sys_script_exec_t '/var/www/html(/.*)?/.*\.cgi' 

接下來,還原任何現有的CGI FIL內容ES:

sudo restorecon -Rv /var/www/html/ 

您還需要允許Apache將允許執行CGI腳本使用下列內容:

sudo setsebool -P httpd_enable_cgi 1 

你應該做的。請注意,如果您的CGI腳本需要讀取/寫入系統中其他文件的內容,則還必須將httpd_sys_rw_content_t上下文應用於這些文件(請參閱下面的示例)。


剛剛遇到這個問題,試圖在CentOS 7(x86_64)系統上安裝Bugzilla(使用CGI)。監控我的httpd的錯誤日誌(sudo tail -f /var/log/httpd/error_log)當觀察到以下錯誤:

[cgi:error] [pid 1825] [client ...:56481] AH01215: (13)Permission denied: exec of '/var/www/html/bugzilla/index.cgi' failed 
[cgi:error] [pid 1825] [client ...:56481] End of script output before headers: index.cgi 

檢查範圍內的應用到我的Bugzilla的安裝,我看到以下內容:

$ ls -Z /var/www/html/bugzilla/ 
... 
-rwxr-x---. apache apache unconfined_u:object_r:httpd_sys_content_t:s0 index.cgi 
... 

然後我用下面的命令許可證Bugzilla的CGI腳本執行以及用於訪問表示CGI腳本讀取./data目錄中的內容:

sudo yum install policycoreutils-python 
sudo semanage fcontext -a -t httpd_sys_script_exec_t '/var/www/html/bugzilla(/.*)?/.*\.cgi' 
sudo semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/bugzilla/data(/.*)?' 
sudo restorecon -Rv /var/www/html/bugzilla/ 
sudo setsebool -P httpd_enable_cgi 1 

檢查應用的上下文顯示期望的結果:

$ ls -Z /var/www/html/bugzilla/ 
... 
-rwxr-x---. apache apache unconfined_u:object_r:httpd_sys_script_exec_t:s0 index.cgi 
... 

Bugzilla應該現在可用。 Bugzilla提供的所有功能可能還有其他策略可以應用;但是,如果需要任何其他策略,我不知道。