> On 24 Nov 2015, at 11:00 PM, Amir Afianian <[email protected]> wrote: > > Hi all. > > I'm a newbie in django and lately I've been trying to use apache as my django > web server to test mod_xsendfile for a project. My environment: ubuntu 14.04, > python 3.4, apache2, django 1.8, having mod_wsgi installed using pip. I also > have downloaded and compiled mod_xsendfile on apache2 > > > > I have several problems though:. > > Problem1: In the documentation provided at here > <https://tn123.org/mod_xsendfile/> it states to set mod_xsendfile on and > provide a path for it in the virtual host configuration; I searched and > noticed the virtual host config takes place in a file named httpd.conf and in > ubuntu 14.04 having apache2 installed it seems that the whole structures has > changed so I found no such file. > Ubuntu and most Linux distributions do not use the standard Apache Software Foundation configuration file layout and instead use their own.
For the details of how Ubuntu does it see: https://help.ubuntu.com/lts/serverguide/httpd.html <https://help.ubuntu.com/lts/serverguide/httpd.html> For Ubuntu I would image though that you don’t need to build mod_xsendfile from source code, simply install the Ubuntu binary package for it and then as per Ubuntu instructions do something like: sudo a2ensite mod_xsendfile The mod_xsendfile argument value may change depending on what the package calls the configuration file it creates in modules-available. May just be ‘xsendfile’. Your would then configure it in your sites files. > Problem2: I am using mod_wsgi-express for running my server and it performs > all the configurations automatically. I have read the documentations in here > <https://pypi.python.org/pypi/mod_wsgi> and here > <http://blog.dscpl.com.au/2015/04/introducing-modwsgi-express.html> but I > couldn't find in any of them being stated where the general configurations > (apache configurations to be specific) are pulled from. > > > > Long story short: my question being: how can I enable mod_xsendfile > considering my environment and the fact that I am using mod_wsgi-express > which generates the configs automatically. > > Note:: I run the server using the following command: $python manage.py > runmodwsgi > > If using mod_wsgi-express, you only need to install mod_xsendfile into the main Apache installation. You don’t need to enable it or configure the main Apache installation. Before I get onto where you would then configure it for mod_wsgi-express, I would highlight that strictly speaking you do not need it. This is because mod_wsgi when used in daemon mode has a similar mechanism to what mod_xsendfile implements, although it is URL based rather than file system path based, that means your code needs to do things a bit differently. The feature in mod_wsgi daemon mode is that a WSGI application can return an empty 200 response with a Location response header where the value of the Location header is, rather than a full URI with ‘http://' <http://'> is a path starting in ‘/‘. That is, is a URL path only. When this is done, mod_wsgi will trigger an internal redirect as a GET and whatever resource matched the URL path for that site, that will be returned. So imagine that if using mod_wsgi-express with Django integration and you had static file assets located in directory at a URL path of ‘/static/stuff’. The WSGI application could return 200, empty response body and Location header with value of ‘/static/stuff/file.txt’ and the file called ‘file.txt’ in the static directory would be served up as the response. Important to stress again, it isn’t a file system path. It is a URL path and that is mapped by mod_wsgi again via Apache. The URL path thus needs to resolve to something, in this case it will map to the static assets directory that Django integration for mod_wsgi sets up. The only problem with this as it stands is that in this case, it means the file matched by the URL path, could also be accessed directory from outside still. That is, would be a public URL. If is a generated/senstive file that is a problem. As Apache doesn’t have a direct equivalent to nginx to private URL namespace for statics often used with nginx X-Accel-Redirect, then you have to use mod_rewrite to create the same effect. To do that you need an Apache configuration snippet like: RewriteCond %{IS_SUBREQ} false RewriteRule ^/static/stuff/ - [F] This would be put in a file called extra.conf and when you run mod_wsgi-express via the admin script you would use: python manage.py runmodwsgi —include-file=extra.conf Note that I haven’t tested that and is a chance that that mod_rewrite rule will not play nice with everything else mod_wsgi-express does. Having seen this though, you are also introduced to the —include-file option. Rather than use 200/Location, you could instead just enable mod_xsendfile and use it. In that case in extra.conf you would add something like: LoadModule xsendfile_module '${MOD_WSGI_MODULES_DIRECTORY}/mod_xsendfile.so’ XSendFile On Then have your application produce X-Sendfile response header referencing a file system path instead. 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/modwsgi. For more options, visit https://groups.google.com/d/optout.
