Instead of seeing my Django view I get a directory listing or NOT FOUND

103 views
Skip to first unread message

Edwardo Hanna

unread,
Jul 14, 2014, 4:30:51 PM7/14/14
to mod...@googlegroups.com
My Django application works fine in the Django server however when I try using Apache, my Django application does either two things.

A:
A URL serves a directory listing : http://192.168.33.102:8787/myapp/

B: 
A URL serves:

Not Found

The requested URL /myapp/ass1v2/ was not found on this server.


Apache/2.2.22 (Ubuntu) Server at 192.168.33.102 Port 8787

I looked at my Apache 2 error log and notice the following. 

[Mon Jul 14 18:57:41 2014] [error] [client 192.168.33.1] File does not exist: /var/www/sampleapp/Java/for_django_1-4/myproject/myproject/myapp/ass1v2
[Mon Jul 14 18:57:41 2014] [error] [client 192.168.33.1] File does not exist: /var/www/sampleapp/Java/for_django_1-4/myproject/myproject/myapp/ass1v2
[Mon Jul 14 18:57:42 2014] [error] [client 192.168.33.1] File does not exist: /var/www/sampleapp/Java/for_django_1-4/myproject/myproject/myapp/ass1v2
[Mon Jul 14 18:57:42 2014] [error] [client 192.168.33.1] File does not exist: /var/www/sampleapp/Java/for_django_1-4/myproject/myproject/myapp/ass1v2
[Mon Jul 14 18:57:42 2014] [error] [client 192.168.33.1] File does not exist: /var/www/sampleapp/Java/for_django_1-4/myproject/myproject/myapp/ass1v2
[Mon Jul 14 18:57:43 2014] [error] [client 192.168.33.1] File does not exist: /var/www/sampleapp/Java/for_django_1-4/myproject/myproject/myapp/ass1v2
[Mon Jul 14 18:57:43 2014] [error] [client 192.168.33.1] File does not exist: /var/www/sampleapp/Java/for_django_1-4/myproject/myproject/myapp/ass1v2
[Mon Jul 14 18:57:43 2014] [error] [client 192.168.33.1] File does not exist: /var/www/sampleapp/Java/for_django_1-4/myproject/myproject/myapp/ass1v2
[Mon Jul 14 18:57:44 2014] [error] [client 192.168.33.1] File does not exist: /var/www/sampleapp/Java/for_django_1-4/myproject/myproject/myapp/ass1v2
[Mon Jul 14 18:57:44 2014] [error] [client 192.168.33.1] File does not exist: /var/www/sampleapp/Java/for_django_1-4/myproject/myproject/myapp/ass1v2
[Mon Jul 14 18:57:44 2014] [error] [client 192.168.33.1] File does not exist: /var/www/sampleapp/Java/for_django_1-4/myproject/myproject/myapp/ass1v2

This is the Apache Virtual Host File:

<VirtualHost *:8787>
ServerAdmin test@localhost

WSGIDaemonProcess sampleapp python-path=/var/www/sampleapp:/var/www/sampleapp/env/lib/python2.7/site-packages
WSGIProcessGroup sampleapp

WSGIScriptAlias / /var/www/sampleapp/Java/for_django_1-4/myproject/myproject/wsgi.py
        #WSGIScriptAlias /myapp/index/ /var/www/sampleapp/Java/for_django_1-4/myproject/myproject/wsgi.py
<Directory /var/www/sampleapp/Java/for_django_1-4/myproject/myproject>
Order allow,deny
Allow from all
</Directory>

Alias /media/ /var/www/sampleapp/Java/for_django_1-4/myproject/myproject/media/
Alias /static/ /var/www/sampleapp/Java/for_django_1-4/myproject/myproject/static/
Alias /myapp/ /var/www/sampleapp/Java/for_django_1-4/myproject/myproject/myapp/

<Directory /var/www/sampleapp/Java/for_django_1-4/myproject/myproject/static/>
#Require all granted
         Order allow,deny
         Allow from all
</Directory>

<Directory /var/www/sampleapp/Java/for_django_1-4/myproject/myproject/media/>
#Require all granted
         Order allow,deny
         Allow from all
</Directory>

<Directory /var/www/sampleapp/Java/for_django_1-4/myproject/myproject/myapp/>
#Require all granted
         Order allow,deny
         Allow from all
</Directory>

<Directory /var/www/sampleapp/Java/for_django_1-4/myproject/myproject>
<Files wsgi.py>
#Require all granted
</Files>
</Directory>

ErrorLog /var/log/apache2/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/access.log combined

</VirtualHost>

This is the urls.py file:

# -*- coding: utf-8 -*-
from django.conf.urls import patterns, include, url
from django.conf import settings
from django.conf.urls.static import static
from django.views.generic.simple import redirect_to

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',

    url(r'^admin/', include(admin.site.urls)),
        (r'^myapp/', include('myproject.myapp.urls')),
    # This was the orginal plan
        # (r'^$', redirect_to, {'url': '/myapp/list/'}), # Just for ease of use.

    (r'^$', redirect_to, {'url': '/myapp/index/'}), # Just for ease of use.

) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

This is myproject.myapp.urls

# -*- coding: utf-8 -*-
from django.conf.urls.defaults import patterns, url

urlpatterns = patterns('myproject.myapp.views',
    url(r'^list/$', 'list', name='list'),
    url(r'^ass1/$', 'ass1', name='ass1'),
    url(r'^ass1v2/$', 'ass1v2', name='ass1v2'),
    url(r'^register/$','register', name='register'), # ADD NEW PATTERN!
    url(r'^login/$', 'user_login', name='login'),
    url(r'^logout/$', 'user_logout', name='logout'),
    url(r'^index/$', 'index', name='index'),
    url(r'^category/(?P<category_name_url>\w+)/$', 'category', name='category'),
    url(r'^indexAddJac444/$', 'indexAddJac444', name='indexAddJac444'),
    url(r'^$', 'index', name='index_2'),
)


This is the wsgi.py File:

import os
import sys
import site

root = os.path.join(os.path.dirname(__file__), '..')
sys.path.insert(0, root)

packages = os.path.join(root,
        '/var/www/sampleapp/env/lib/python2.7/site-packages')
sys.path.insert(0, packages)
site.addsitedir(packages)


#A
sys.path.append('/var/www/sampleapp/Java-auto-grader-edx/for_django_1-4/myproject/myproject')
sys.path.append('/var/www/sampleapp/Java-auto-grader-edx/for_django_1-4/myproject')
sys.path.append('/var/www/sampleapp/Java-auto-grader-edx/for_django_1-4')

#Monday July 14:B
sys.path.append('/var/www/sampleapp/Java-auto-grader-edx')
sys.path.append('/var/www/sampleapp')

#sys.path.append('/var/www/sampleapp/Java-auto-grader-edx/for_django_1-4/myproject/')

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")

# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

# Apply WSGI middleware here.
# from helloworld.wsgi import HelloWorldApplication
# application = HelloWorldApplication(application)

Does anyone have suggestions as to why I would be getting the directory listing and NOT FOUND errors? Thanks.

Graham Dumpleton

unread,
Jul 14, 2014, 4:43:36 PM7/14/14
to mod...@googlegroups.com
For a start, the Alias directive:

Alias /myapp/ /var/www/sampleapp/Java/for_django_1-4/myproject/myproject/myapp/

is overriding the WSGIScriptAlias directive for that sub URL.

Comment out that Alias directive and see what happens.

Graham

--
You received this message because you are subscribed to the Google Groups "modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to modwsgi+u...@googlegroups.com.
To post to this group, send email to mod...@googlegroups.com.
Visit this group at http://groups.google.com/group/modwsgi.
For more options, visit https://groups.google.com/d/optout.

Edwardo Hanna

unread,
Jul 14, 2014, 4:46:51 PM7/14/14
to mod...@googlegroups.com
Yes I removed that line. Still the problem.

Graham Dumpleton

unread,
Jul 14, 2014, 4:50:21 PM7/14/14
to mod...@googlegroups.com

On 14/07/2014, at 1:46 PM, Edwardo Hanna <hanna....@gmail.com> wrote:

> Yes I removed that line. Still the problem.

Just inside of:

<VirtualHost *:8787>

add:

Deny from all

Restart Apache and try again.

This is to validate that the VirtualHost is actually being used. Using a VirtualHost with an IP only can some times cause issues if not setup properly.

If the VirtualHost is actually being used, you should now get a Forbidden response.

Any chance you can't map a host name to that IP and add ServerName so is a proper name based virtual host setup?

Graham

Edwardo Hanna

unread,
Jul 14, 2014, 5:06:13 PM7/14/14
to mod...@googlegroups.com
Hello Graham!

I get:

deny not allowed here
Action 'start' failed.
The Apache error log may have more information.

Does this confirm what you are saying? Thanks

Graham Dumpleton

unread,
Jul 14, 2014, 5:08:40 PM7/14/14
to mod...@googlegroups.com
No.

Use:

<Location />
Deny from all
</Location>

inside of the VirtualHost instead.

The error you got does at least tell us the file is being read though. :-)

Graham

Edwardo Hanna

unread,
Jul 14, 2014, 5:17:28 PM7/14/14
to mod...@googlegroups.com
Thanks! Yes after using using: http://192.168.33.102:8787/myapp/ I get:

Forbidden

You don't have permission to access /myapp/ on this server.

Graham Dumpleton

unread,
Jul 14, 2014, 5:51:52 PM7/14/14
to mod...@googlegroups.com

On 14/07/2014, at 2:17 PM, Edwardo Hanna <hanna....@gmail.com> wrote:

Thanks! Yes after using using: http://192.168.33.102:8787/myapp/ I get:

Comment out that <Location /> block with the Deny from all in it.

Then comment out all the Alias directives.

Finally, you are missing in:

        <Directory /var/www/sampleapp/Java/for_django_1-4/myproject/myproject>
<Files wsgi.py>
#Require all granted
</Files>
</Directory>

the:

Order allow,deny
Allow from all

so add that to that as well where you have 'Require all granted' commented out.

When replying please then show the complete current configuration for the VirtualHost rather than just your new reply. By not including what went before I loose context and have to go search back through older messages.

Graham

Edwardo Hanna

unread,
Jul 14, 2014, 6:17:38 PM7/14/14
to mod...@googlegroups.com
Hello Graham, thanks, I have made the updates in this post. I also just watched your video at PyConAU 2010. I was trying to take note if anything could help me avoid the directory listing and the NOT FOUND pages. Thanks


<VirtualHost *:8787>
        #<Location /> 
        #Deny from all 
        #</Location>  
ServerAdmin test@localhost

WSGIDaemonProcess sampleapp python-path=/var/www/sampleapp:/var/www/sampleapp/env/lib/python2.7/site-packages
WSGIProcessGroup sampleapp

WSGIScriptAlias / /var/www/sampleapp/Java-auto-grader-edx/for_django_1-4/myproject/myproject/wsgi.py
<Directory /var/www/sampleapp/Java-auto-grader-edx/for_django_1-4/myproject/myproject>
Order allow,deny
Allow from all
</Directory>

Alias /media/ /var/www/sampleapp/Java-auto-grader-edx/for_django_1-4/myproject/myproject/media/
Alias /static/ /var/www/sampleapp/Java-auto-grader-edx/for_django_1-4/myproject/myproject/static/
Alias /myapp/ /var/www/sampleapp/Java-auto-grader-edx/for_django_1-4/myproject/myproject/myapp/

<Directory /var/www/sampleapp/Java-auto-grader-edx/for_django_1-4/myproject/myproject/static/>
#Require all granted
         Order allow,deny
         Allow from all
</Directory>

<Directory /var/www/sampleapp/Java-auto-grader-edx/for_django_1-4/myproject/myproject/media/>
#Require all granted
         Order allow,deny
         Allow from all
</Directory>

<Directory /var/www/sampleapp/Java-auto-grader-edx/for_django_1-4/myproject/myproject/myapp/>
#Require all granted
         Order allow,deny
         Allow from all
</Directory>

<Directory /var/www/sampleapp/Java-auto-grader-edx/for_django_1-4/myproject/myproject>
<Files wsgi.py>
#Require all granted
        Order allow,deny
        Allow from all

Graham Dumpleton

unread,
Jul 15, 2014, 9:46:54 PM7/15/14
to mod...@googlegroups.com
I am confused. Did you actually comment out all the Alias directives to see at least whether the request hot handled by the WSGI application at all? The configuration you have below didn't have them commented out.

BTW, I would very much suggest that rather than using a Django web application, that you go back and validate your Apache configuration using a simple WSGI hello world application such as in:


Ensure you can get that working at least.

If that works, then we need to look at what is producing the 404.

Graham


Reply all
Reply to author
Forward
0 new messages