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

22 views
Skip to first unread message

Aaron Krister Johnson

unread,
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>

# DISABLE CACHING
<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;"
</IfModule>

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`:

#!/home/untwelve_admin/untwelve.dreamhosters.com/bin/python3.12

import sys

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

sys.path.append("UnTwelveDotOrg")

app = loadapp(
    "config:/home/untwelve_admin/untwelve.dreamhosters.com/UnTwelveDotOrg/development.ini"
)

if __name__ == "__main__":
    WSGIServer(app).run()


Thanks for any insights you can provide!

Best,
Aaron


Thierry Florac

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

Best regards,
Thierry

--
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 pylons-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/2df33b45-96b9-4812-9eed-72f58861af12n%40googlegroups.com.

Jonathan Vanasco

unread,
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

unread,
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
Forward
0 new messages