Prevent Apache2 from executing CGI in Static Directory

I am running an Apache 2 web server running on Ubuntu 20.04 LTS. I have a Python CGI handler enabled for the /var/www/html directory, which is the DocumentRoot. I am wondering how to exclude a certain directory from running CGI for Python files.
Here in my CGI config:

<Directory "/var/www/html">
    Options +ExecCGI
    AddHandler cgi-script .py
        <IfModule mod_rewrite.c>
                RewriteEngine On
                RewriteCond %{REQUEST_FILENAME} !-d
                RewriteCond %{REQUEST_FILENAME}\.py -f
                RewriteRule ^(.*)$ $1.py
        </IfModule>
</Directory>

<Directory "/var/www/html/static/cdn">
        DirectoryIndex disabled
        Options +Indexes -ExecCGI
        AllowOverride None
        Require all granted
</Directory>

In the /static/cdn directory, I want .py files to be served just like any other static file, instead of being executed as CGI. Here is a tree of the cdn directory:

.
├── checkForUpdates.exe
├── checkForUpdates.py
└── findLogErrors
    ├── botCriteria.json
    ├── cleanup.json
    ├── findLogErrors.exe
    └── version.json

1 directory, 6 files

I am able to see the indexes of the directory in the web browser, as desired. I am able to view or download any file from this directory except checkForUpdates.py. The server is not trying to execute it as CGI, it's giving a 403. The permissions on checkForUpdates.py are the same as the other files:

nbroyles@webserver:/var/www/html/static/cdn$ ls -altr
total 15548
-rwxrwxr-x 1 www-data web 15901526 Nov 17 11:37 checkForUpdates.exe
drwxrwxr-x 7 www-data web     4096 Nov 19 11:13 ..
drwxrwxr-x 2 www-data web     4096 Dec 23 09:41 findLogErrors
drwxrwxr-x 3 www-data web     4096 Dec 23 09:49 .
-rwxrwxr-x 1 www-data web     2072 Dec 23 09:49 checkForUpdates.py

How can I view the .py file just like any of the .json or .exe files? I'm sure there's something simple I'm missing in my config. Any help is greatly appreciated!


Solution 1:

You need to add SetHandler default-handler in <Directory "/var/www/html/static/cdn">