Unable to run cgi program on apache2 server (with some mod_jk configuration)

14 Views Asked by At

In a apache2 server which have enabled mod_jk to access tomcat10 contexts, it was also enabled and configured the mod_cgid to run programs from the folder /var/www/apps/cgi-bin.

But when I try access the cgi program through the url https://domain/cgi-bin/program, the server return error 404.

In the VirtualHost configuration file (below), if I remove the line JkMount /app/* ajp13_worker, the cgi can be reached, but now when I access https://domain/ I no longer got the desired page (that comes from a tomcat10 context), only a directory listing.

Is it any way to have both JkMount /app/* ajp13_worker and the cgi configuration?

What I have tried: adding 'JkUnMount /cgi-bin/* ajp13_worker' to the VirtualHost configuration file do not solve this problem.

file: /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 /* apps_worker
        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>

file: /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 /* apps_worker
        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>

file: /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>

this is the directory listing for /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
0

There are 0 best solutions below