无法在 apache2 服务器上运行 cgi 程序(使用一些 mod_jk 配置)

无法在 apache2 服务器上运行 cgi 程序(使用一些 mod_jk 配置)

在已启用 mod_jk 来访问 tomcat10 上下文的 apache2 服务器中,它还启用并配置了 mod_cgid 来从文件夹运行程序/var/www/apps/cgi-bin

但是当我尝试通过 url 访问 cgi 程序时https://domain/cgi-bin/program,服务器返回error 404

在 VirtualHost 配置文件(如下)中,如果我删除该行JkMount /app/* ajp13_worker,则可以访问 cgi,但现在当我访问时,https://domain/我不再获得所需的页面(来自 tomcat10 上下文),只有一个目录列表。

有没有办法可以同时拥有JkMount /app/* ajp13_workercgi 配置?

我尝试过的方法:将“JkUnMount /cgi-bin/* ajp13_worker”添加到 VirtualHost 配置文件并不能解决这个问题。

文件:/etc/apache2/sites-available/apps.conf

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin [email protected]
        DocumentRoot /var/www/apps
        ServerName domain

        JkMount /app/* ajp13_worker
        JkMount /auth/* ajp13_worker
        JkMount /mail/* ajp13_worker
        JkMount /pay/* ajp13_worker
        JkMount /admin/* ajp13_worker
        JkMount /inbox/* ajp13_worker

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
RewriteEngine on
RewriteCond %{SERVER_NAME} =domain
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

文件:/etc/apache2/sites-available/apps-le-ssl.conf

<IfModule mod_ssl.c>
<VirtualHost *:443>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin [email protected]
        DocumentRoot /var/www/apps
        ServerName domain

        JkMount /app/* ajp13_worker
        JkMount /auth/* ajp13_worker
        JkMount /mail/* ajp13_worker
        JkMount /pay/* ajp13_worker
        JkMount /admin/* ajp13_worker
        JkMount /inbox/* ajp13_worker

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf

SSLCertificateFile /etc/letsencrypt/live/domain/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/domain/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

文件:/etc/apache2/conf-available/serve-cgi-bin.conf

<IfModule mod_alias.c>
        <IfModule mod_cgi.c>
                Define ENABLE_USR_LIB_CGI_BIN
        </IfModule>

        <IfModule mod_cgid.c>
                Define ENABLE_USR_LIB_CGI_BIN
        </IfModule>

        <IfDefine ENABLE_USR_LIB_CGI_BIN>
                ScriptAlias /cgi-bin/ /var/www/apps/cgi-bin/
                <Directory "/var/www/apps/cgi-bin/">
                        AllowOverride None
                        Options +ExecCGI
                        Require all granted
                </Directory>
        </IfDefine>
</IfModule>

这是的目录列表/var/www/apps

root@tomcat:/var/www/apps# ls -la
total 12
drwxr-xr-x 3 www-data www-data 4096 Feb 19 20:47 .
drwxr-xr-x 7 root root 4096 Feb 19 20:47 ..
drwxr-xr-x 2 www-data www-data 4096 Feb 19 20:53 cgi-bin
root@tomcat:/var/www/apps# cd cgi-bin
root@tomcat:/var/www/apps/cgi-bin# ls -la
total 212
drwxr-xr-x 2 www-data www-data 4096 Feb 19 20:53 .
drwxr-xr-x 3 www-data www-data 4096 Feb 19 20:47 ..
-rwxr-xr-x 1 www-data www-data 202584 Feb 19 20:53 program
-rwxr-xr-x 1 www-data www-data 103 Feb 19 20:53 teste.cgi

相关内容