matsair
By:
matsair

403 Forbidden using Flask, WSGI and Apache2

October 27, 2016 199 views
Apache Debian

I'm getting 403 Forbidden when trying to access my Flask app from my local notebook using my Droplet's IP. Any help would be appreciated!

This is my Apache2 error log:

[Thu Oct 27 08:33:22.308733 2016] [authz_core:debug] [pid 24390:tid 140263676557056] mod_authz_core.c(809): [client 134.155.212.122:60940] AH01626: authorization result of Require all denied: denied
[Thu Oct 27 08:33:22.308770 2016] [authz_core:debug] [pid 24390:tid 140263676557056] mod_authz_core.c(809): [client 134.155.212.122:60940] AH01626: authorization result of <RequireAny>: denied
[Thu Oct 27 08:33:22.308774 2016] [authz_core:error] [pid 24390:tid 140263676557056] [client 134.155.212.122:60940] AH01630: client denied by server configuration: /home/mats/var/www/TVApp/tvapp.wsgi

This is my conf file:

<VirtualHost *:80>
                ServerName xx.xxx.xxx.xx
                ServerAdmin xx@xxx.xxx
                WSGIScriptAlias / /home/mats/var/www/TVApp/tvapp.wsgi
                <Directory /home/mats/var/www/TVApp/TVApp/>
                        Require all granted
                </Directory>
                Alias /static /home/mats/var/www/TVApp/TVApp/static
                <Directory /home/mats/var/www/TVApp/TVApp/static/>
                        Require all granted
                </Directory>
                ErrorLog ${APACHE_LOG_DIR}/error.log
                LogLevel debug
                CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

My wsgi file:

#!/usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/TVApp/")

from TVApp import app as application
application.secret_key = 'Add your secret key'

This is the output of apachectl -S:

AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
VirtualHost configuration:
*:80                   46.101.208.32 (/etc/apache2/sites-enabled/TVApp.conf:1)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex watchdog-callback: using_defaults
Mutex default: dir="/var/lock/apache2" mechanism=fcntl 
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33
1 Answer

I am not seeing anything in your VirtualHost configuration that should cause the error you're seeing. I have a couple questions to try and get started debugging this:

1.) Is this the only Virtualhost defined in your configuration? Is the default one still present? It's possible that your requests are hitting the wrong VirtualHost handler, causing errors that don't make sense in context to the one you think is being used.

2.) Have you restarted apache after editing your virtualhost configuration?

3.) Do you get any different results if you try removing the sections related to your /static directory?

Have another answer? Share your knowledge.