【问题标题】:Apache2 run perl script as Directory IndexApache2 运行 perl 脚本作为目录索引
【发布时间】:2013-10-08 23:17:31
【问题描述】:

我想要它,所以当您访问 https://device.my.server.com/reg 时,服务器会运行 /var/www/html/reg/registrar.cgi 这是一个 perl 脚本。现在它只是列出目录的内容。我知道脚本有效并且为每个人设置了可执行位。服务器是 CentOS linux HTTPD 2.2.15。我不能使用 mod-redirect 或重写,我需要像下面尝试的那样使用核心指令来执行此操作。

<VirtualHost device.my.server.com:443>
DocumentRoot /var/www/html/reg
ServerName device.my.server.com
ErrorLog logs/device.my.server.com-error_log
CustomLog logs/device.my.server-access_log co
SSLEngine on
SSLCertificatekeyFile /etc/httpd/ssl/device.my.server.com.key
SSLCertificateFile /etc/httpd/ssl/device.my.server.com.crt
SSLCertificateChainFile /etc/httpd/ssl/chain.crt
<Directory /var/www/html/reg>
    Options ExecCGI
    AddHandler cgi-script .cgi
    DirectoryIndex registrar.cgi
    Order allow,deny
    Allow from all
    #SetHandler cgi-script
</Directory>
</VirtualHost>

【问题讨论】:

    标签: linux perl apache cgi virtualhost


    【解决方案1】:

    问题是您正试图像这样访问您的VirtualHostDocumentRoot

    https://device.my.server.com/reg
    

    什么时候你应该像这样访问它:

    https://device.my.server.com/
    

    如果您想使用以前的网址,请将您的 DocumentRoot 更改为 /var/www/html

    还要确保在测试时使用VirtualHost 指令中指定的完整地址(即https://device.my.server.com/,而不是http://device.my.server.com/https://device/)。

    在我的测试中,当我访问https://device.my.server.com/test时,下面的配置会执行/var/www/html/test/foo.cgi(显然我已经编辑了主机/域名):

    <VirtualHost device.my.server.com:443>
        DocumentRoot /var/www/html
        ServerName device.my.server.com
        SSLEngine on
        SSLCertificateFile /path/to/cert
        SSLCertificateKeyFile /path/to/key
    
        <Directory /var/www/html/test>
            Options ExecCGI
            AddHandler cgi-script .cgi
            DirectoryIndex foo.cgi
            Order allow,deny
            Allow from all
        </Directory>
    </VirtualHost>
    

    您也可以考虑关闭索引作为额外的安全措施:

    Options -Indexes
    

    这将告诉 Apache 不要创建目录列表,即使 DirectoryIndex 指定的文件丢失。

    【讨论】:

    • 禁用索引只是显示我现在在访问 URL 而不是列出内容时被禁止。脚本仍未运行。
    • 如果我将 URL 直接指向 cgi 文件,它会列出文件的文本而不是执行它,但是如果我指向 cgi-bin 目录中相同 cgi 文件的副本,它运行良好。
    • @GreggLeventhal 如果它显示您的脚本文本,那么它不会作为 CGI 执行(显然)。添加Options ExecCGIAddHandler cgi-script .cgi 后,您是否重新加载了配置?
    • @GreggLeventhal 另外,您使用的具体网址是什么?
    • 我像你说的那样将 documentroot 切换到 /var/www/html 并且正在使用“(https) device.my.server.com/reg”
    猜你喜欢
    • 1970-01-01
    • 2019-03-07
    • 1970-01-01
    • 1970-01-01
    • 2012-10-18
    • 1970-01-01
    • 1970-01-01
    • 2010-09-26
    • 2011-09-05
    相关资源
    最近更新 更多