Chocobozzz / PeerTube

ActivityPub-federated video streaming platform using P2P directly in your web browser
https://joinpeertube.org/
GNU Affero General Public License v3.0
13.05k stars 1.5k forks source link

Nginx/S3 redirect documentation for multiple buckets #3618

Closed agates closed 3 years ago

agates commented 3 years ago

I have configured remote S3 storage as shown here, with 1 bucket for each of the specified folders (3 total, for videos, streaming-playlists, and redundancy). I am mounting with s3fs.

Parts of the documentation concerned:

https://github.com/Chocobozzz/PeerTube/blob/5f59cf077fd9f9c0c91c7bb56efbfd5db103bff2/support/nginx/peertube#L235-L242

Describe the desired information/correction

Given the example Nginx configuration, it is not clear to me how to redirect the URLs to the S3 buckets. Perhaps documented static API endpoints associated to the correct base/example URLs would help.

rigelk commented 3 years ago

@agates the tutorial expects one bucket for all 3 folders.

ku9nov commented 3 years ago

@rigelk Hello. I'm doing the same at the moment and for some reason when I do this I get this result:

root @ ip-10-0-11-136: / var / www / peertube # mount --bind $ S3_STORAGE / videos / var / www / peertube / storage / videos
mount: / var / www / peertube / storage / videos: special device / var / www / peertube / s3-storage / videos does not exist.

folders should already be created? I can mount the bucket with this command:

s3fs mybucket /var/www/peertube/s3-storage -o allow_other -o use_path_request_style -o uid=1000 -o gid=1000 -o nonempty -o url=https://s3.amazonaws.com/ -o passwd_file=/etc/passwd-s3fs

But then the video is not loaded into the bucket. If I create folders manually, and without url, then the video is loaded into the bucket in the video folder, but when loading it gives such an error on peertube.

Jan 19 11:19:50 ip-10-0-11-136 peertube[848880]:           "name": "Moonlight - Electric Cello (Inspired by Beethoven) - The Piano Guys",
Jan 19 11:19:50 ip-10-0-11-136 peertube[848880]:           "remote": false,
Jan 19 11:19:50 ip-10-0-11-136 peertube[848880]:           "commentsEnabled": true,
Jan 19 11:19:50 ip-10-0-11-136 peertube[848880]:           "downloadEnabled": true,
Jan 19 11:19:50 ip-10-0-11-136 peertube[848880]:           "waitTranscoding": true,
Jan 19 11:19:50 ip-10-0-11-136 peertube[848880]:           "nsfw": false,
Jan 19 11:19:50 ip-10-0-11-136 peertube[848880]:           "privacy": "3",
Jan 19 11:19:50 ip-10-0-11-136 peertube[848880]:           "channelId": 1,
Jan 19 11:19:50 ip-10-0-11-136 peertube[848880]:           "state": 2,
Jan 19 11:19:50 ip-10-0-11-136 peertube[848880]:           "duration": null,
Jan 19 11:19:50 ip-10-0-11-136 peertube[848880]:           "url": "https://mybucket/videos/watch/e0d3c3e4-ee3e-4236-89c1-7ddbbb93c201",
Jan 19 11:19:50 ip-10-0-11-136 peertube[848880]:           "updatedAt": "2021-01-19T11:19:50.327Z",
Jan 19 11:19:50 ip-10-0-11-136 peertube[848880]:           "createdAt": "2021-01-19T11:19:50.327Z"
Jan 19 11:19:50 ip-10-0-11-136 peertube[848880]:         },
Jan 19 11:19:50 ip-10-0-11-136 peertube[848880]:         "validatorKey": "isVideoDuration",
Jan 19 11:19:50 ip-10-0-11-136 peertube[848880]:         "validatorName": null,
Jan 19 11:19:50 ip-10-0-11-136 peertube[848880]:         "validatorArgs": [],
Jan 19 11:19:50 ip-10-0-11-136 peertube[848880]:         "original": {
Jan 19 11:19:50 ip-10-0-11-136 peertube[848880]:           "stack": "Error: \"NaN\" is not a valid duration.\n    at Object.throwIfNotValid (/var/www/peertube/versions/peertube-v3.0.0/dist/server/models/utils.js:92:15)\n    at VideoModel.tsli>
Jan 19 11:19:50 ip-10-0-11-136 peertube[848880]:           "message": "\"NaN\" is not a valid duration."
Jan 19 11:19:50 ip-10-0-11-136 peertube[848880]:         }
Jan 19 11:19:50 ip-10-0-11-136 peertube[848880]:       }
Jan 19 11:19:50 ip-10-0-11-136 peertube[848880]:     ]
Jan 19 11:19:50 ip-10-0-11-136 peertube[848880]:   }
Jan 19 11:19:50 ip-10-0-11-136 peertube[848880]: }

nginx conf:

    set $cdn https://s3.amazonaws.com/mybucket/;
    rewrite ^/static/webseed/(.*)$ $cdn/videos/$1 redirect;
    rewrite ^/static/(.*)$         $cdn/$1        redirect;
    rewrite ^/static/webseed/(.*)$ /videos/$1 break;
    rewrite ^/static/(.*)$         /$1        break;

Ubuntu 20. Peertube 3. AWS s3 bucket. Сould you help me? Thank you. Regards.

agates commented 3 years ago

@agates the tutorial expects one bucket for all 3 folders.

I understand, that is why I opened this. If it's simpler for maintenance for me to migrate to one bucket, I'll have to do that.

However, the documentation could better explain the endpoints for redirect, no?

normen commented 3 years ago

You just put your buckets public URL in there, as written in the docs. I didn't have any issues with that. You do have to configure your S3 space manually though (CORS and ACL) to be able to access the files in the browser: NGINX:

        set $cdn https://peertube.s3.hidrive.strato.com;
        rewrite ^/static/webseed/(.*)$ $cdn/videos/$1 redirect;
        rewrite ^/static/(.*)$         $cdn/$1        redirect;

Set ACL command (aws command line tool):

  aws s3api \
    --endpoint-url https://s3.hidrive.strato.com \
    put-bucket-policy \
    --bucket peertube \
    --policy file://peertube-policy.json

peertube-policy.json:

   {
     "Version": "2012-10-17",
     "Statement": [
       {
         "Effect": "Allow",
         "Principal": "*",
         "Action": "s3:GetObject",
         "Resource": "arn:aws:s3:::peertube/*"
       }
    ]
 }

Set CORS command:

  aws s3api \
    --endpoint-url https://s3.hidrive.strato.com \
    put-bucket-cors \
    --bucket peertube \
    --cors-configuration file://peertube-cors.json

peertube-cors.json:

 {
    "CORSRules": [
      {
        "AllowedOrigins": ["*"],
        "AllowedHeaders": ["*"],
        "AllowedMethods": ["GET"],
        "MaxAgeSeconds": 3000
      }
    ]
 }

This setup works fine for me except that live video can't be stored after the stream - this is because the whole combined file gets uploaded each time a part gets appended, causing an overload after some time. A limitation of s3fs.

agates commented 3 years ago

The question was raised with regard to using multiple separate buckets, hence documentation.

Chocobozzz commented 3 years ago

Closing this issue in favour of https://github.com/Chocobozzz/PeerTube/issues/3661