How to rename processes
Rename apache (or any) processes to be easily identified from ps output.
- apache
- wsgi
- process
Rename apache (or any) processes to be easily identified from ps output.
Add this to your apache config: `<Directory /path/to/media> WSGIAccessScript /path/to/access.wsgi </Directory>` Save the snippet as access.wsgi. Set up the paths, and do some authorization checking.
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).
Add this to your middleware to log errors to the Apache error log when running under mod_wsgi.
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.
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.
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).
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>
** 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"
This very simple middleware will set the 'user' attribute of a mod_python request.. this way the username is logged into the apache log ... useful when making webalizer statistics to see the activity of users .. (http://sct.sphene.net)
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>
11 snippets posted so far.