2

I'm running into an issue with setting a WSGIScriptAlias in Apache, where attempting to use the alias is giving a 404 error due to trying to reach the "literal" URL. Here's the test set-up in my Apache2 sites-available/000-default.conf (mimicking the mod_wsgi Quick Start Guide):

DocumentRoot /var/www/html
WSGIScriptAlias /wsgi_test /var/www/html/test.wsgi
<Directory /var/www/html>
        Order allow,deny
        Allow from all
</Directory>

After restarting Apache2 and going to mydomain.com/wsgi_test, a 404 page is displayed. The first line of Apache's error.log file below shows the server attempting to access the URL path wsgi_test in DocumentRoot, not the aliased file path:

AH00128: File does not exist: /var/www/html/wsgi_test
AH01964: Connection to child 1 established (server nathanclonts.com:443)
(70007)The timeout specified has expired: [client 67.161.148.188:33883] AH01991: SSL input filter read failed.

The file /var/www/html/test.wsgi has the same code as the above-mentioned Quick Start Guide:

def application(environ, start_response):
    status = '200 OK'
    output = b'Hello World!'
    response_headers = [('Content-type', 'text/plain'),
                    ('Content-Length', str(len(output)))]
    start_response(status, response_headers)
    return [output]

With permissions set to:

-rwxrw-r-- 1 username www-data   278 Apr 16 11:31 test.wsgi

Does anyone have suggestions on where to look for other configuration that may be affecting this, or any other debugging tips?

What's odd is that I have set up another (Django) application with mod_wsgi that is currently working in the same VirtualHost, but obviously I'm missing something in this test.

NathanC
  • 75
  • 2
  • 10
  • 1
    Where is the Django configuration defined relative to what you added? If the Django application is at path of '/', then what you add here must be before that, else the matching of '/' for the Django application will take precedence. – Graham Dumpleton Apr 18 '17 at 02:18
  • It turns out that it was just a problem with the general Alias configuration: the [WSGIScript]Aliases were defined for `VirtualHost *`, but not for `VirtualHost *:433` (the server uses SSL). Adding them to the `VirtualHost *:433 file fixed it. Thanks for the suggestion though, good thing to keep in mind! – NathanC Apr 19 '17 at 02:43

1 Answers1

0

This was resolved by updating the <VirtualHost *:443> configuration file to include the WSGIScriptAlias line (as the server uses SSL), instead of having WSGIScriptAlias under the <VirtualHost *> configuration.

I wasn't aware that all Aliases needed to be included in the 443 port to function, but eventually worked it out after playing with a vanilla Alias and locating which files they were defined in with:

grep -R "Alias" /etc/apache2/*
NathanC
  • 75
  • 2
  • 10