Question about serving video and audio (e.g .mp4 and .ogg)

Skip to first unread message

Aaron Krister Johnson

Mar 23, 2024, 4:08:55 PMMar 23
to pylons-discuss
Hi all,

I have a pyramid app on Dreamhost, and they are reverting from using Ruby's passenger back to fcgi fro shared hosting accounts. The server runs Apache, and I have control of .htaccess configuration.

At the moment, I am able to serve static files by using `config.add_static_view`, but it does not appear to be working for things like videos hosted on site (.mp4) nor audio (.ogg).

I thought to bypass `add_static_view` and have Apache serve static assets itself, but it's brought no joy, since apparently, my setup doesn't allow `Alias` directives, and the `RewriteCond` for files doesn't play well with Pyramid's layout, with or without `add_static_view`. The basic site seems to work better when I use Pyramid to serve, but like I said, video and audio files are blocked somehow. How do I serve .mp4 and .ogg? Do I have to get into declaring things iwth the `mimetypes` lib?

Here's my .htaccess, for reference:

$ cat .htaccess
#Disables GZIP
SetEnv no-gzip 1
#Turns off the expires headers for Apache
<IfModule mod_expires.c>
  ExpiresActive Off

<IfModule mod_headers.c>
  Header set Cache-Control "no-cache, no-store, must-revalidate"
  Header set Pragma "no-cache"
  Header set Expires 0
  Header always set Content-Security-Policy "upgrade-insecure-requests;"

Options +ExecCGI
AddHandler fcgid-script .fcgi
SetHandler fcgid-script
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi/$1 [QSA,L]

And here is my `dispatch.fcgi`:


import sys

from paste.deploy import loadapp
from flup.server.fcgi_fork import WSGIServer


app = loadapp(

if __name__ == "__main__":

Thanks for any insights you can provide!


Thierry Florac

Mar 23, 2024, 10:51:45 PMMar 23
Hi Aaron,
Could you explain what is not working when you use Pyramid static views to handle videos or audios files?

Best regards,

You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit

Jonathan Vanasco

Mar 25, 2024, 2:43:55 PMMar 25
to pylons-discuss
Unless you need to lock those files down with pyramid auth, I would isolate them away for Apache to serve.

I am very familiar with Dreamhost, and running fcgi stuff on it.  I keep some subversion/trac stuff on it - I really need to upgrade those to git!

I would avoid serving anything static on Dreamhost through Pyramid.  They have some throttling and process monitoring on their virtualization stack - and do not have a nice cleanup of old fcgi processes.  All your static assets are going to be competing for limited resources with the urls that can only be handled by the Pyramid app.

If you can map the apache subdir to the pyramid static folder, that would be ideal.  Another option is serving the static files as a separate subdomain, mapping the static dir to that domain on dreamhost, and using a toggle in your app to handle the url prefix for the assets (same domain on testing environment, subdomain on production).

Aaron Krister Johnson

Apr 6, 2024, 7:56:30 PMApr 6
to pylons-discuss
I finally figured out what was happening....I ended up resetting my venv and re-installing my app to its venv via `pip install -e .`

This seems to have done the trick, so it must have been in a weird state.

Thanks for all your help here!
Reply all
Reply to author
0 new messages