Login

Tag "apache"

Snippet List

Log username in Apache access logs

This is a piece of middleware that reports the logged-in user back to Apache. This should cause the logged-in user to be present in the apache access log. Put it in `settings.MIDDLEWARE_CLASSES` after `AuthenticationMiddleware`. This has been tested with mod_python but does [not work with wsgi](http://groups.google.com/group/modwsgi/browse_thread/thread/8785a99d4ba7ee99).

  • log
  • apache
  • mod_python
Read More

Python fixup handler for Apache

If you have another application in the same Apache virtual host and also want to use the authentication from Django - this might help. It uses the Django cookie - so it will not work in another Apache virtual host.

  • authentication
  • apache
  • fixup-handler
Read More

django under apache / mod_fcgid

This recipe uses a modified version of Robin Dunn's fcgi.py module that adapts fcgi to wsgi and lets you run Django under mod_fcgid. One good thing about mod_fcgid is that it does all process management for you, which makes this setup quite straightforward. Also, since Robin's module works both in a cgi and fcgi context, switching a django site between cgi and fastcgi is a one-liner in the apache config, without any changes to python code or django config. CGI may be handy for development, since it loads all code (including changed code) on every request, yet lets you work in an environment that resembles production. Apache configuration examples are found in the comment at the beginning of the python module.

  • apache
  • fastcgi
  • cgi
  • mod_fcgid
Read More

Autoreload Apache on project modifications

This script will reload apache when any modifications are detected in a folder - useful only if the development server or mod_python's reload does not suit your needs for testing. It requires Linux 2.6.13+, Python 2.5, and the [development version of pyinotify](http://seb.dbzteam.com/pages/pyinotify-dev.html).

  • apache
  • reload
  • autoreload
  • modified
  • linux
  • pyinotify
Read More

Custom mod_python AuthenHandler

This handler is useful if you serve static/media files directly from Apache only to authenticated users. It checks if a user is not anonymous (and therefore logged in) and redirects to the login site if needed. The following apache config activates the handler: <Location "/site_media/company1"> #SetHandler None ##Uncomment if you serve static files in the same virtual host PythonOption DJANGO_SETTINGS_MODULE mysite.settings PythonAuthenHandler mysite.myhandler PythonPath "['/path/to/project'] + sys.path" Require valid-user </Location>

  • apache
  • mod_python
  • auth
  • static
Read More

Single Django App behind multiple Apache Proxies

** Django Proxied Behind Apache Path** Middleware and Context Processor for django applications behind a proxy like Apache's mod_proxy. Setting an HTTP header with the base path of the django application in the Apache mod_proxy configuration, we can pull that variable out of the request and adjust our template URIs and redirects. This allows us to serve the same Django application out from behind multiple VirtualHosts at different URL paths. Example use in templates: <a href="{{ base_path }}/login/">Login</a> Example Apache configuration: <LocationMatch ^/path/to/django/app/.*> RequestHeader set X-Base-Path "/path/to/django/app" </LocationMatch> RewriteRule ^/path/to/django/app/(.*) http://django-host:8080/$1 [P,L] In settings.py: VHOST_HEADER = "HTTP_X_BASE_PATH"

  • apache
  • virtualhost
  • mod_proxy
  • path
Read More

apache authentication via cookies

Enables cookie based authentication with apache. I needed user authentication for some static files, but couldn't use the method described [here](http://www.djangoproject.com/documentation/apache_auth/) as this prompts the user for his credentials, making him log in twice. There is some overhead in the code, because it runs all request middleware components (only session and auth would be needed). All arguments described in the link above are supported. I use it like this in the apache config: <Location "/protected/location"> PythonPath "['/path/to/proj/'] + sys.path" PythonOption DJANGO_SETTINGS_MODULE myproj.settings PythonOption DjangoPermissionName '<permission.codename>' PythonAccessHandler my_proj.modpython #this should point to accesshandler SetHandler None </Location>

  • authentication
  • apache
Read More

11 snippets posted so far.