TIL: Some Apache Config Options
I run Apache as my main web server. There’s rarely a need to modify anything but when there is, it’s usually quite simple. That’s mainly why I never bothered to switch to nginx. Over the course of last month I had to change two things, here’s a short summary.
I wanted to share some markdown (
.md) files but my configuration forced download (or at least didn’t request in-lining) even though it’s just a text file that could be rendered in the browser.
I learned that this behavior depends on
Content-Disposition HTTP header.
Apache has a module
mod_headers that allows setting arbitrary headers, along with
FilesMatch I came up with the following solution:
<IfModule mod_headers.c> <FilesMatch ".+\.md$"> Header set Content-Disposition inline Header set Content-Type text/plain </FilesMatch> </IfModule>
Today I wanted to add a static files hosting to a VirtualHost that was serving as a reverse proxy until now.
I knew about
Alias directive but it didn’t work out of the box — the requests for aliased path
were still proxied to an application that didn’t know how to handle them.
It turned out that the priority of
ProxyPass is higher than
Alias so I had to explicitly write an exclusion for the aliased directory like so:
(...) ProxyPass /static ! Alias /static /path/to/my/static ProxyPass / http://127.0.0.1:1337/ ProxyPassReverse / http://127.0.0.1:1337/ (...)