You are probably going to have to ask on Django users list how to
protect static files served by Django under its own security
mechanisms. Is not usually how its down. Often you have to have static
assets downloadable to even see the log in page, so you can't protect
everything.

What stuff there is about using Django password database for
protecting stuff under Apache using Basic auth is detailed in:

http://code.google.com/p/modwsgi/wiki/AccessControlMechanisms

Graham

On 31 August 2012 05:53, hhummel <[email protected]> wrote:
> Things went much better fixing the name of the wsgi file, but I've
> struggling with the static files.  I don't have a lot of users and I'm not
> that worried about performance, but I'm interested in having the static
> content password projected.  Therefore I'd like password protected under the
> django views rather than server the static content through apache.
>
> Here's the httpd.conf:
>
> <Directory /var/www/django/static>
>     Order deny,allow
>     Allow from all
> </Directory>
>
> WSGIScriptAlias / /var/www/django/mysite/apache/django.wsgi
>
> <Directory /var/www/django/mysite/apache/mysite>
>
>     Order allow,deny
>     Allow from all
> </Directory>
>
> #Alias /static/ /var/www/django/static/
>
> If I remove the comment # from the Alias command, everything works, but my
> static content is exposed on the public web, too.  With the Alias command
> commented out, I don't see the static content anymore, although the template
> appears correctly.
>
> I used the collectstatic command, (although it' not really relevant as I
> don't have lots of apps), so the static content is in
> /var/www/django/static.
>
> Here is the settings.py pertaining to STATIC:
>
> STATIC_ROOT = '/var/www/django/static/'
>
> # URL prefix for static files.
> # Example: "http://media.lawrence.com/static/";
> STATIC_URL = '/static/'
>
> # Additional locations of static files
> STATICFILES_DIRS = (
>     # Put strings here, like "/home/html/static" or "C:/www/django/static".
>     # Always use forward slashes, even on Windows.
>     # Don't forget to use absolute paths, not relative paths.
> )
>
> I added the instrumentation to the settings.py recommended in
> http://blog.dscpl.com.au/2010/03/improved-wsgi-script-for-use-with.html
>
> I see verbose output in the error log, so I'll try to abstract what might be
> useful.  /var/forecast_charts is the URL
>
> [Thu Aug 30 15:22:12 2012] [notice] Apache/2.2.22 (Unix) DAV/2
> mod_python/3.3.1 Python/2.7.1 mod_wsgi/3.4 PHP/5.3.13 mod_ssl/2.2.22
> OpenSSL/1.0.0j-fips mod_perl/2.0.4 Perl/v5.12.4 configured -- resuming
> normal operations
> [Thu Aug 30 15:22:12 2012] [info] Server built: Feb 13 2012 14:50:23
> [Thu Aug 30 15:22:12 2012] [info] mod_wsgi (pid=14827): Attach interpreter
> ''.
> [Thu Aug 30 15:22:12 2012] [info] mod_wsgi (pid=14829): Attach interpreter
> ''.
> [Thu Aug 30 15:22:12 2012] [info] mod_wsgi (pid=14828): Attach interpreter
> ''.
> [Thu Aug 30 15:22:16 2012] [info] mod_wsgi (pid=14822): Create interpreter
> '127.0.0.1|'.
> [Thu Aug 30 15:22:16 2012] [info] [client 127.0.0.1] mod_wsgi (pid=14822,
> process='', application='127.0.0.1|'): Loading WSGI script
> '/var/www/django/mysite/apache/django.wsgi'., referer:
> http://127.0.0.1/var/forecast_charts
> [Thu Aug 30 15:22:17 2012] [error] __name__ = mysite.settings
> [Thu Aug 30 15:22:17 2012] [error] __file__ =
> /var/www/django/mysite/apache/../mysite/settings.pyc
> [Thu Aug 30 15:22:17 2012] [error] os.getpid() = 14822
> [Thu Aug 30 15:22:17 2012] [error] os.getcwd() = /
> [Thu Aug 30 15:22:17 2012] [error] os.curdir = .
> [Thu Aug 30 15:22:17 2012] [error] sys.path =
> ['/var/www/django/mysite/apache/..',
> '/usr/lib/python2.7/site-packages/rpy2-2.2.6dev_20120811-py2.7-linux-x86_64.egg',
> '/usr/lib64/python27.zip', '/usr/lib64/python2.7',
> '/usr/lib64/python2.7/plat-linux2', '/usr/lib64/python2.7/lib-tk',
> '/usr/lib64/python2.7/lib-old', '/usr/lib64/python2.7/lib-dynload',
> '/usr/lib64/python2.7/site-packages',
> '/usr/lib64/python2.7/site-packages/PIL',
> '/usr/lib64/python2.7/site-packages/gst-0.10',
> '/usr/lib64/python2.7/site-packages/gtk-2.0',
> '/usr/lib/python2.7/site-packages',
> '/usr/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info',
> '/var/www/django/mysite', '/var/www/django/static']
>
> ...
>
> [Thu Aug 30 15:22:17 2012] [error] sys.modules.has_key('mysite') = True
> [Thu Aug 30 15:22:17 2012] [error] sys.modules['mysite'].__name__ = mysite
> [Thu Aug 30 15:22:17 2012] [error] sys.modules['mysite'].__file__ =
> /var/www/django/mysite/apache/../mysite/__init__.pyc
> [Thu Aug 30 15:22:17 2012] [error] os.environ['DJANGO_SETTINGS_MODULE'] =
> mysite.settings
> [Thu Aug 30 15:22:17 2012] [info] mod_wsgi (pid=14824): Create interpreter
> '127.0.0.1|'.
>
> Here's django.wsgi.  I used the version from django 1.4 but used the apache
> parallel directory as per your recommendations:
> import os
> import sys
>
> #Takes advantage of setting up parallel file structure for
> mysite/apache/wsgi.py and mysite/mysite/settings.py
> root = os.path.join(os.path.dirname(__file__), '..')
> sys.path.insert(0, root)
>
> #Seems to need the absolute path as well
> sys.path.append('/var/www/django/mysite')
> sys.path.append('/var/www/django/static')
>
> os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.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()
>
>
> Any advice on why the static content isn't serving through mod_wsgi?
>
> Thanks again for your help, this is great software!
>
>
> Harry
>
>
> On Tuesday, August 28, 2012 9:24:22 PM UTC-4, Graham Dumpleton wrote:
>>
>> Don't you mean:
>>
>> WSGIScriptAlias /myapp  /var/www/wsgi-scripts/myapp/wsgi.py
>>
>> You have to modify the target file based on where it is. Can't copy
>> documentation blindly.
>>
>> Graham
>>
>> On 29 August 2012 10:59, hhummel <[email protected]> wrote:
>> > I'm having trouble with getting mod_wsgi going on FC15 linux.  I'm
>> > trying to run the simple "Hello World" demo.
>> >
>> > Here's httpd.conf:
>> >
>> > LoadModule wsgi_module modules/mod_wsgi.so
>> >
>> > WSGIScriptAlias /myapp /var/www/wsgi-scripts/myapp.wsgi
>> >
>> > <Directory /var/www/wsgi-scripts>
>> >     Order allow,deny
>> >     Allow from all
>> > </Directory>
>> >
>> > The app is in /var/www/wsgi-scripts/myapp/wsgi.py, and is copied
>> > directly from the documentation:
>> >
>> > def application(environ, start_response):
>> >     status = '200 OK'
>> >     output = 'Hello World!'
>> >
>> >     response_headers = [('Content-type', 'text/plain'),
>> >                         ('Content-Length', str(len(output)))]
>> >     start_response(status, response_headers)
>> >
>> >     return [output]
>> >
>> > When I restart the server and use the URL 127.0.0.1/mapp is see this
>> > error log:
>> >
>> > [Tue Aug 28 20:44:26 2012] [notice] Apache/2.2.22 (Unix) DAV/2
>> > mod_python/3.3.1 Python/2.7.1 mod_wsgi/3.4 PHP/5.3.13 mod_ssl/2.2.22
>> > OpenSSL/1.0.0j-fips mod_perl/2.0.4 Perl/v5.12.4 configured -- resuming
>> > normal operations
>> > [Tue Aug 28 20:44:26 2012] [info] Server built: Feb 13 2012 14:50:23
>> > [Tue Aug 28 20:44:26 2012] [info] mod_wsgi (pid=556): Attach interpreter
>> > ''.
>> > [Tue Aug 28 20:44:26 2012] [info] mod_wsgi (pid=555): Attach interpreter
>> > ''.
>> > [Tue Aug 28 20:44:32 2012] [error] [client 127.0.0.1] Target WSGI script
>> > not found or unable to stat: /var/www/wsgi-scripts/myapp.wsgi
>> >
>> > Permissions on the file:
>> > [harry@mars mysite]$ ls -l
>> > total 4
>> > -rw-r--r-- 1 harry harry 1428 Aug 28 17:21 wsgi.py
>> >
>> >  Permissions on the dir:
>> > [harry@mars apache]$ ls -l
>> > total 4
>> > drwxrwxr-x 2 harry harry 4096 Aug 28 18:25 mysite
>> >
>> > I'm kind of stuck what else to try.  Can you help?
>> >
>> > Many thanks,
>> >
>> > Harry
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups "modwsgi" group.
>> > To view this discussion on the web visit
>> > https://groups.google.com/d/msg/modwsgi/-/G98EjEg88ZUJ.
>> > To post to this group, send email to [email protected].
>> > To unsubscribe from this group, send email to
>> > [email protected].
>> > For more options, visit this group at
>> > http://groups.google.com/group/modwsgi?hl=en.
>> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "modwsgi" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/modwsgi/-/2Zl25hjvkeQJ.
>
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/modwsgi?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"modwsgi" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/modwsgi?hl=en.

Reply via email to