Apache配置實現cgi

來源:互聯網
上載者:User

標籤:linux   apache   cgi   

裝完Apache,需要修改apache的設定檔:

nano /etc/httpd/conf/httpd.conf

設定檔中有

ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"這個指令,指示了預設的cgi-bin的路徑。

/var/www/cgi-bin/,在設定檔中也可以看到。

還需要配置

AddHandler cgi-script .cgi .pl

該配置預設被注釋掉了,設定了cgi的尾碼名

編寫一個cgi檔案,內容如下:

#!/bin/bashecho "Content-type: text/html"echo ""echo "Hello World"

注意,該檔案必須是要UNIX檔案格式的,可以editpro等工具編寫。將該檔案命名為first.cgi,然後放入/var/www/cgi-bin/目錄中。

然後運行http://wusqcentos:9000/cgi-bin/first.cgi,可以發現,有錯誤

650) this.width=650;" style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;border-top:0px;border-right:0px;padding-top:0px;" title="clipboard" border="0" alt="clipboard" src="http://s3.51cto.com/wyfs02/M02/58/EF/wKiom1TBEw2zetDdAAFwRH_vyN4514.jpg" height="299" />

有錯誤不可怕,預設的httpd的錯誤記錄檔在/var/log/httpd/error_log裡可以看到,也可以去http的軟串連中訪問/etc/httpd/logs/error_log

開啟error_log檔案,可以看到如下的錯誤:

[Thu Jan 22 09:06:54 2015] [error] [client 192.168.6.2] (13)Permission denied: exec of ‘/var/www/cgi-bin/first.cgi‘ failed

[Thu Jan 22 09:06:54 2015] [error] [client 192.168.6.2] Premature end of script headers: first.cgi

說明了許可權被拒絕了。將first.cgi的使用權限設定成755

chmod 755 /var/www/cgi-bin/first.cgi

再次運行http://wusqcentos:9000/cgi-bin/first.cgi,發現就正常顯示了

同樣的,可以編輯一個perl檔案,也可以以cgi的方式運行

#!/usr/bin/perlprint "Content-type: text/html\n\n";print "Hello, World.";


本文出自 “一隻部落格” 部落格,請務必保留此出處http://cnn237111.blog.51cto.com/2359144/1607177

Apache配置實現cgi

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.