不顯示 CGI 腳本的標準方法是什麼?

不顯示 CGI 腳本的標準方法是什麼?

userdir我已經使用Apache 中的 mod設定了一個 CGI 目錄。我使用盡可能通用的配置,以使它們適用於我的筆記型電腦上的其他使用者。我已經可以使用以下 URL 運行腳本了:

http://localhost/~tomas/cgi-bin/hw.cgi

public_html但我還在伺服器的根目錄中放置了一個鏈接/var/www/html,因此當localhost調用 URL 時,我會獲取帶有指向我的目錄的鏈接的索引localhost/tomas。該連結工作正常,並顯示另一個索引,即我的用戶之一。現在,私有 cgi-bin 位於,因此我可以在獲取私有索引時/home/*/public_html/cgi-bin看到。cgi-bin現在,當我進入這個目錄時,我會得到另一個帶有 CGI 的索引。這對我來說很好,儘管我不確定這是否被認為是安全的。但如果我從那裡調用 CGI,它不會執行並顯示。這就是問題。

據我所知,這是關於Apache不查看

http://localhost/tomas/cgi-bin/hw.cgi

作為

http://localhost/~tomas/cgi-bin/hw.cgi

我一直在尋找一個可以使其工作的指令,但找不到它。我甚至不太確定我可以使用什麼——指令還是其他什麼?

這是我的usermod.conf

<IfModule mod_userdir.c>
    UserDir public_html
    UserDir disabled root

    <Directory /home/*/public_html>
        AllowOverride FileInfo AuthConfig Limit Indexes
        Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
        <Limit GET POST OPTIONS>
            Require all granted
        </Limit>
        <LimitExcept GET POST OPTIONS>
            Require all denied
        </LimitExcept>
    </Directory>

    <Directory /home/*/public_html/cgi-bin>
        Options ExecCGI
        AddHandler cgi-script .cgi
    </Directory>
</IfModule>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

答案1

由於cgi-bin可以透過單獨的路徑存取該目錄,因此一種方法是將Directory具有備用路徑的部分複製到另一個路徑的正下方,例如:

<Directory /var/www/html/*/cgi-bin>
    Options ExecCGI
    AddHandler cgi-script .cgi
</Directory>

這也應該禁用目錄列表。

如果您希望啟用索引,請新增IndexesOptions透過變更為使其繼承其父選項,ExecCGI例如+ExecCGI

<Directory /var/www/html/*/cgi-bin>
    Options Indexes ExecCGI
    AddHandler cgi-script .cgi
</Directory>

我更喜歡使用Options Indexes ExecCGIoverOptions +ExecCGI因為這樣你就不會繼承任何不需要的選項。

相關內容