mediacms-io / mediacms

MediaCMS is a modern, fully featured open source video and media CMS, written in Python/Django and React, featuring a REST API.
https://mediacms.io
GNU Affero General Public License v3.0
2.67k stars 495 forks source link

Video Playback Through NGINX Proxy Not Working #729

Closed andrewjkrull closed 1 year ago

andrewjkrull commented 1 year ago

Describe the issue Video won't play through an Nginx Proxy

To Reproduce docker-compose up Existing Nginx Server. Was able to get previous issues sorted out from this post: https://github.com/mediacms-io/mediacms/discussions/585 Upload Big Buck Bunny through proxy Playback works going directly to server Playback doesn't work going through proxy

Expected behavior Should have video playback through proxy

Environment (please complete the following information):

Additional context I really want to like MeidaCMS and get this working. I am trying to host my daughter's volleyball games for family and friends to watch but I have been struggling to get all the bits working. I was really hoping using the included docker files would make things easier.

I should add, I used the NGINX configuration found in the referenced discussion (JustinBack) which basically got everything working but video playback. Before adding the two lines to settings.py and updating my NGINX config to the provided one, everything above the About link didn't work.

andrewjkrull commented 1 year ago

When I hit the site and click on the video here are the logs from NGINX (cd /var/log/nginx; tail -f access.log error.log zmk_.log vbzmk.log):

==> access.log <==
134.238.214.224 - - [06/Mar/2023:10:01:15 -0600] "GET /view?m=1bYt8UWlf HTTP/2.0" 200 2825 "https://volleyball.zennakrull.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36"
134.238.214.224 - - [06/Mar/2023:10:01:15 -0600] "GET /api/v1/media/1bYt8UWlf HTTP/2.0" 200 886 "https://volleyball.zennakrull.com/view?m=1bYt8UWlf" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36"
134.238.214.224 - - [06/Mar/2023:10:01:15 -0600] "GET /api/v1/playlists?author=admin HTTP/2.0" 200 63 "https://volleyball.zennakrull.com/view?m=1bYt8UWlf" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36"
134.238.214.224 - - [06/Mar/2023:10:01:15 -0600] "GET /api/v1/users HTTP/2.0" 200 261 "https://volleyball.zennakrull.com/view?m=1bYt8UWlf" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36"
134.238.214.224 - - [06/Mar/2023:10:01:15 -0600] "GET /api/v1/media/1bYt8UWlf/comments HTTP/2.0" 200 63 "https://volleyball.zennakrull.com/view?m=1bYt8UWlf" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36"

And logs from MediaCMS (tail -f ~/docker/mediacms/logs/*) Also tried getting logs from web-1 and nothing there.

[2023-03-06 10:01:15,542: INFO/MainProcess] Received task: save_user_action[c7a3af83-db59-48b0-9c82-67ea13cb1569]
[2023-03-06 10:01:15,559: INFO/ForkPoolWorker-7] Task save_user_action[c7a3af83-db59-48b0-9c82-67ea13cb1569] succeeded in 0.015485143987461925s: False
andrewjkrull commented 1 year ago

Solved it!

Looked through some documentation on Jellyfin and tried some of their options for proxy. Here is my NGINX server config. What is commented out in the location block is what I had and below the proxy_pass is what I added from aforementioned documentation.

server {

    server_name video.exmaple.com;

    client_max_body_size 5G;
    charset utf-8;

    # Security / XSS Mitigation Headers
    # NOTE: X-Frame-Options may cause issues with the webOS app
    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    location / {
        #proxy_set_header X-Forwarded-Host $host;
        #proxy_set_header X-Forwarded-Server $host;
        #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        #proxy_set_header X-Forwarded-Proto https;
        proxy_pass http://192.168.1.20:80; # 8012 being the forwarded port of the web container in docker

        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Protocol $scheme;
        proxy_set_header X-Forwarded-Host $http_host;

        # Disable buffering when the nginx proxy gets very resource heavy upon streaming
        proxy_buffering off;

    }

    listen [::]:443 ssl; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/video.exmaple.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/video.exmaple.com/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}

server {
    if ($host = video.exmaple.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    server_name video.exmaple.com;

    listen 80;
    return 404; # managed by Certbot
}