Score:0

Apache2: Why do I get a 403 Forbidden error?

gb flag

I've been messing with this for days :(

Why do I get a 403 Forbidden error at example.com/contact?

Is this a file/folder permissions, Apache user, virtualhosts or Python issue?

I'm trying to run a Django app at /contact but the first issue is the 403 error.

  • I'm running Ubuntu 20.04.3 LTS
  • Apache 2.4.41 installed and is running
  • Python 3.8 and Django installed
  • libapache2-mod-wsgi-py3 installed and enabled
  • apachectl configtest Syntax OK
  • All files chowned to www-data:www-data
  • Directories chmod +x
  • example.com/index.html works

/var/log/apache2/access.log is empty

/var/log/apache2/error.log contains:

[mpm_prefork:notice] [pid 69090] AH00163: Apache/2.4.41 (Ubuntu) OpenSSL/1.1.1k mod_wsgi/4.6.8 Python/3.8 configured -- resuming normal operations

[core:notice] [pid 69090] AH00094: Command line: '/usr/sbin/apache2'

The .htaccess file at root has

 RewriteEngine on
 ServerSignature Off
 Options All -Indexes

This is my public_html file structure:

enter image description here

/etc/apache2/sites-available/default-ssl.conf:

  <IfModule mod_ssl.c>
    <VirtualHost _default_:443>
        ServerAdmin webmaster@localhost
    
        DocumentRoot /var/www/html
    
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    
        SSLEngine on
    
        SSLCertificateFile  /etc/ssl/certs/ssl-cert-snakeoil.pem
        SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
    
        <FilesMatch "\.(cgi|shtml|phtml|php)$">
                    SSLOptions +StdEnvVars
        </FilesMatch>
        <Directory /usr/lib/cgi-bin>
                    SSLOptions +StdEnvVars
        </Directory>
    
    
    Alias /static /var/www/html/example.com/public_html/contact/static
    Alias /media /var/www/html/example.com/public_html/contact/media

    <Directory /var/www/html/example.com/public_html/contact/static>
        Require all granted
    </Directory>

    <Directory /var/www/html/example.com/public_html/contact/media>
        Require all granted
    </Directory>

    WSGIScriptAlias /contact/contact /var/www/html/example.com/public_html/contact/contact/wsgi.py

    WSGIDaemonProcess contact python-home=/var/www/html/example.com/public_html/contact/contact

    WSGIProcessGroup contact

    WSGISocketPrefix run/wsgi

    <Directory /var/www/html/example.com/public_html/contact/contact>
        <Files wsgi.py>
            Require all granted
            AllowOverride None
            Allow from all
        </Files>
    </Directory>

        </VirtualHost>
</IfModule>
Score:0
cn flag
Bob

When there is no Indexdocument in a directory Apache httpd cannot display anything. The typical alternative for Apache, to display a directory listing instead, has been disabled by setting -Indexes in the Options.

BlueDogRanch avatar
gb flag
Thanks, that was easy.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.