Apache2将perl脚本作为目录索引运行

时间:2022-10-05 20:25:20

I want it so when you visit https://device.my.server.com/reg the server runs /var/www/html/reg/registrar.cgi which is a perl script. Right now it is just listing the contents of the directory. I know the script works and has executable bit set for everyone. Server is CentOS linux HTTPD 2.2.15. I cannot use mod-redirect or rewrite, I need to do this using the core directives like I am trying below.

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

<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>

1 个解决方案

#1


1  

The problem is that you're trying to access the DocumentRoot of your VirtualHost like this:

问题是您尝试访问VirtualHost的DocumentRoot,如下所示:

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

when you should be accessing it like this:

当你应该这样访问它时:

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

If you want to use the former URL, change your DocumentRoot to /var/www/html.

如果要使用以前的URL,请将DocumentRoot更改为/ var / www / html。

Also make sure when you test that you use the full address specified in your VirtualHost directive (i.e. https://device.my.server.com/, not http://device.my.server.com/ or https://device/).

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

In my test, the following configuration executes /var/www/html/test/foo.cgi when I access https://device.my.server.com/test (obviously I have edited host/domain name):

在我的测试中,当我访问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>

You might also consider turning off indexes as an extra security measure:

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

Options -Indexes

This will tell Apache not to create a directory listing, even if the file specified by DirectoryIndex is missing.

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

#1


1  

The problem is that you're trying to access the DocumentRoot of your VirtualHost like this:

问题是您尝试访问VirtualHost的DocumentRoot,如下所示:

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

when you should be accessing it like this:

当你应该这样访问它时:

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

If you want to use the former URL, change your DocumentRoot to /var/www/html.

如果要使用以前的URL,请将DocumentRoot更改为/ var / www / html。

Also make sure when you test that you use the full address specified in your VirtualHost directive (i.e. https://device.my.server.com/, not http://device.my.server.com/ or https://device/).

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

In my test, the following configuration executes /var/www/html/test/foo.cgi when I access https://device.my.server.com/test (obviously I have edited host/domain name):

在我的测试中,当我访问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>

You might also consider turning off indexes as an extra security measure:

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

Options -Indexes

This will tell Apache not to create a directory listing, even if the file specified by DirectoryIndex is missing.

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