The following has been tested on Ubuntu 12.04 and 14.04. Other recipes, suggestions, clarifications, corrections welcome!
These instructions assume you have (or will) run sudo ./setup.py install
with the default configurations options.
You can get all of the dependencies from apt:
$ sudo apt-get install apache2 libapache2-mod-wsgi-py3
Next enable to require modules:
sudo a2enmod headers expires
Next edit the site configuration file /etc/apache2/sites-enabled/000-default.conf
with your editor of choice (you'll need root privileges; the name may be different; if there is no site symlinked in the directory, enable the site with, for example a2ensite 000-default.conf
).
Now add something to this affect:
ExpiresActive On
ExpiresDefault "access plus 5184000 seconds"
AllowEncodedSlashes On
WSGIDaemonProcess loris user=loris group=loris processes=10 threads=15 maximum-requests=10000
WSGIScriptAlias /loris /var/www/loris/loris.wsgi
WSGIProcessGroup loris
Note: from Python 3.8 and later, you will get a RuntimeError: fork not supported for subinterpreters
when rendering JPEG2000 source images. To fix this, change the WSGIScriptAlias to the following:
WSGIScriptAlias /loris /var/www/loris/loris.wsgi process-group=loris application-group=%{GLOBAL}
Explanation:
ExpiresActive On
andExpiresDefault
sets theCache-Control
andExpires
headers, e.g. with the setting above responses will include (assuming I made the request atSat, Nov 23 2013 19:45:20 GMT
):
< Cache-Control: max-age=5184000
< Expires: Wed, 22 Jan 2014 19:45:20 GMT
5184000 = 60 days.
(Loris is setting the Last-Modified
header based on the file system metadata.)
-
AllowEncodedSlashes On
lets%2F
though in requests (they're allowed but must be escaped in the identifier portion of the URI). Depending on your hosting environment, this may need to be explicitly declared inside a VirtualHosts container asAllowEncodedSlashes
is not inherited by VirtualHosts if declared in a global context (see Apache Bug 46830). -
WSGI Flags. Have a look at the mod-wsgi configuration guidelines. In general is seems like a good idea to prefer threads over processes; (check out this answer on serverfault).
If you would like Loris's access logs to be kept in a separate file you can add:
SetEnvIf Request_URI ^/loris loris
CustomLog ${APACHE_LOG_DIR}/loris-access.log combined env=loris
The first argument to SetEnvIf Request_URI
should match the first argument to WSGIScriptAlias
above, plus a leading ^
.
On RedHat only you'll likely need to add:
WSGISocketPrefix /var/run/wsgi
as well. See: Location of Unix Sockets.
Finally, restart Apache and have a look (start at http://{your_server}/loris).
Proceed to Developer Notes (optional) or go Back to README