Skip to content
Snippets Groups Projects
Commit a8204415 authored by Stéphane Diemer's avatar Stéphane Diemer
Browse files

Changed cache setup and cache conf (refs #20384).

parent c90ce4c1
No related branches found
No related tags found
No related merge requests found
...@@ -25,38 +25,52 @@ def vhost_write_cmds(dir_path, name, server_name, **data): ...@@ -25,38 +25,52 @@ def vhost_write_cmds(dir_path, name, server_name, **data):
def setup(interactive=True): def setup(interactive=True):
dir_path = utils.get_dir(__file__) dir_path = utils.get_dir(__file__)
cmds = [ cmds = [
'apt-get install --yes nginx uwsgi uwsgi-plugin-python3', 'apt-get remove -y apache2'
'apt-get install -y nginx',
'rm -f /etc/nginx/sites-enabled/default', 'rm -f /etc/nginx/sites-enabled/default',
'rm -f /etc/nginx/sites-enabled/default.conf',
] ]
hosts = list() hosts = list()
# FTP: videos vhost need_uwsgi = False
# FTP vhost (deprecated)
if os.path.exists('/var/www/videos'): if os.path.exists('/var/www/videos'):
cmds.append('cp %s/crossdomain.xml /var/www/videos/crossdomain.xml' % dir_path) cmds.append('cp %s/crossdomain.xml /var/www/videos/crossdomain.xml' % dir_path)
server_name = utils.get_conf('FTP_SERVER_NAME') or 'videos' server_name = utils.get_conf('FTP_SERVER_NAME') or 'videos'
cmds.extend(vhost_write_cmds(dir_path, 'videos', server_name)) cmds.extend(vhost_write_cmds(dir_path, 'videos', server_name))
hosts.append(server_name) hosts.append(server_name)
# Wowza: streaming vhost # Wowza vhost (deprecated)
if os.path.exists('/var/www/streaming'): if os.path.exists('/var/www/streaming'):
cmds.append('cp %s/crossdomain.xml /var/www/streaming/crossdomain.xml' % dir_path) cmds.append('cp %s/crossdomain.xml /var/www/streaming/crossdomain.xml' % dir_path)
server_name = utils.get_conf('WOWZA_SERVER_NAME') or 'streaming' server_name = utils.get_conf('WOWZA_SERVER_NAME') or 'streaming'
cmds.extend(vhost_write_cmds(dir_path, 'streaming', server_name)) cmds.extend(vhost_write_cmds(dir_path, 'streaming', server_name))
hosts.append(server_name) hosts.append(server_name)
# MediaServer: mediaserver-msuser vhost # MediaServer vhost (mediaserver-msuser)
if os.path.exists('/home/msuser/msinstance'): if os.path.exists('/home/msuser/msinstance'):
need_uwsgi = True
server_name = utils.get_conf('MS_SERVER_NAME') or 'mediaserver' server_name = utils.get_conf('MS_SERVER_NAME') or 'mediaserver'
cmds.extend(vhost_write_cmds(dir_path, 'mediaserver-msuser', server_name, cmds.extend(vhost_write_cmds(dir_path, 'mediaserver-msuser', server_name,
secret=utils.get_conf('MS_SECRET') or 'secret', worker_ip=utils.get_conf('CELERITY_WORKER_IP') or '127.0.1.1')) secret=utils.get_conf('MS_SECRET') or 'secret', worker_ip=utils.get_conf('CELERITY_WORKER_IP') or '127.0.1.1'))
hosts.append(server_name) hosts.append(server_name)
# Monitor: msmonitor vhost # Monitor vhost
if os.path.exists('/home/msmonitor/msmonitor'): if os.path.exists('/home/msmonitor/msmonitor'):
need_uwsgi = True
server_name = utils.get_conf('MONITOR_SERVER_NAME') or 'msmonitor' server_name = utils.get_conf('MONITOR_SERVER_NAME') or 'msmonitor'
cmds.extend(vhost_write_cmds(dir_path, 'msmonitor', server_name)) cmds.extend(vhost_write_cmds(dir_path, 'msmonitor', server_name))
hosts.append(server_name) hosts.append(server_name)
# SkyReach: skyreach vhost # SkyReach vhost
if os.path.exists('/home/skyreach/htdocs'): if os.path.exists('/home/skyreach/htdocs'):
need_uwsgi = True
server_name = utils.get_conf('CM_SERVER_NAME') or 'skyreach' server_name = utils.get_conf('CM_SERVER_NAME') or 'skyreach'
cmds.extend(vhost_write_cmds(dir_path, 'skyreach', server_name)) cmds.extend(vhost_write_cmds(dir_path, 'skyreach', server_name))
hosts.append(server_name) hosts.append(server_name)
# Cache vhost
if os.path.exists('/var/www/cache'):
cmds.append('cp %s/crossdomain.xml /var/www/cache/crossdomain.xml' % dir_path)
server_name = utils.get_conf('CACHE_SERVER_NAME') or 'cache'
cmds.extend(vhost_write_cmds(dir_path, 'cache', server_name, source_server=utils.get_conf('CACHE_SOURCE') or 'http://undefined'))
hosts.append(server_name)
if need_uwsgi:
cmds.append('apt-get install -y uwsgi uwsgi-plugin-python3')
utils.run_commands(cmds) utils.run_commands(cmds)
# Update hosts file # Update hosts file
rc, hostname = utils.exec_cmd('hostname') rc, hostname = utils.exec_cmd('hostname')
......
proxy_cache_path /tmp/nginx-uc-cache levels=1:2 keys_zone=uc-cache:10m max_size=10g inactive=300s;
server {
listen 80 default_server;
listen 443 default_server ssl;
server_name {{ server_name }};
root /var/www/cache/;
access_log /var/log/nginx/access_cache.log;
error_log /var/log/nginx/error_cache.log;
location /crossdomain {
}
location /streaming/ {
# Live
location ~ \.m3u8$ {
rewrite ^/(.*)$ /$1? break;
proxy_pass {{ source_server }};
proxy_cache uc-cache;
# do not consider secure urls as new files
proxy_cache_key $scheme$proxy_host$uri;
# only one request at a time will be allowed to populate a new cache element
proxy_cache_lock on;
proxy_cache_min_uses 1;
proxy_cache_use_stale updating;
# how long should the data be kept in the cache
proxy_cache_valid 200 1s;
# instruct browser never to cache this
expires -1;
# headers
proxy_ignore_headers Cache-Control;
proxy_ignore_headers Set-Cookie;
proxy_ignore_headers X-Accel-Expires;
proxy_ignore_headers Expires;
proxy_hide_header Pragma;
add_header X-Cache $upstream_cache_status;
}
location ~ \.ts$ {
rewrite ^/(.*)$ /$1? break;
proxy_pass {{ source_server }};
proxy_cache uc-cache;
# do not consider secure urls as new files
proxy_cache_key $scheme$proxy_host$uri;
# only one request at a time will be allowed to populate a new cache element
proxy_cache_lock on;
proxy_cache_min_uses 1;
proxy_cache_use_stale updating;
# how long should the data be kept in the cache
proxy_cache_valid 200 10s;
# instruct browser to cache this
expires 2s;
# headers
proxy_ignore_headers Cache-Control;
proxy_ignore_headers Set-Cookie;
proxy_ignore_headers X-Accel-Expires;
proxy_ignore_headers Expires;
proxy_hide_header Pragma;
add_header X-Cache $upstream_cache_status;
}
}
location /resources/ {
# VOD
location ~ \.(m3u8|ts|mp4|mp3|oga|ogv|ogg|mov|flv)$ {
rewrite ^/(.*)$ /$1? break;
proxy_pass {{ source_server }};
proxy_cache uc-cache;
# do not consider secure urls as new files
proxy_cache_key $scheme$proxy_host$uri;
# only one request at a time will be allowed to populate a new cache element
proxy_cache_lock on;
proxy_cache_min_uses 1;
proxy_cache_use_stale updating;
# how long should the data be kept in the cache
proxy_cache_valid 200 7d;
# instruct browser to cache this
expires 7d;
# headers
proxy_ignore_headers Cache-Control;
proxy_ignore_headers Set-Cookie;
proxy_ignore_headers X-Accel-Expires;
proxy_ignore_headers Expires;
proxy_hide_header Pragma;
add_header X-Cache $upstream_cache_status;
}
}
location / {
# only urls to video and audio files are allowed, discard any requested path for other urls
rewrite ^/(.*)$ /index.html? break;
}
}
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import utils
def setup(interactive=True):
dir_path = utils.get_dir(__file__)
rc, hostname = utils.exec_cmd('hostname')
if rc != 0 or not hostname:
hostname = 'cache'
cmds = [
'mkdir -p /var/www/cache',
dict(
line='write',
template='%s/index.html' % dir_path,
target='/var/www/cache/index.html',
params=dict(hostname=hostname),
),
]
utils.run_commands(cmds)
#!/bin/bash
source /root/envsetup/global-conf.sh
sed -i "s@\[CLIENT\]@$(hostname)@" default
sed -i "s@\[CACHE_DIR\]@${CACHE_DIR}@" default
sed -i "s@\[CACHE_NAME\]@${CACHE_NAME}@" default
sed -i "s@\[CACHE_SIZE\]@${CACHE_SIZE}@" default
sed -i "s@\[CACHE_PROXY_PASS_STREAM\]@${CACHE_PROXY_PASS_STREAM}@" default
sed -i "s@\[CACHE_PROXY_PASS_VOD\]@${CACHE_PROXY_PASS_VOD}@" default
sed -i "s@\[CLIENT\]@$(hostname)@" index.html
apt-get purge -y apache2
apt-get install nginx -y
mv default /etc/nginx/sites-enabled/default
mv index.html /usr/share/nginx/html/index.html
# create crossdomain
cat << EOF >> /var/www/html/crossdomain.xml
<cross-domain-policy>
<allow-access-from domain="*" secure="false"/>
<site-control permitted-cross-domain-policies="all"/>
</cross-domain-policy>
EOF
chmod 777 /var/www/html/crossdomain.xml
update-rc.d nginx defaults
service nginx restart
proxy_cache_path [CACHE_DIR] levels=1:2 keys_zone=[CACHE_NAME]:10m max_size=[CACHE_SIZE]g inactive=5m;
server {
listen 80 default_server;
server_name [CLIENT];
location /nginx_status {
stub_status on;
allow 127.0.0.1;
deny all;
}
location ~* /crossdomain.xml {
alias /var/www/html/crossdomain.xml;
}
# cache configuration for live
location ~* /live/.*\.(m3u8).*$ {
proxy_cache [CACHE_NAME];
proxy_pass [CACHE_PROXY_PASS_STREAM]; # http only
# only one request at a time will be allowed to populate a new cache element
proxy_cache_lock on;
proxy_ignore_headers Cache-Control;
proxy_ignore_headers Set-Cookie;
proxy_ignore_headers X-Accel-Expires;
proxy_ignore_headers Expires;
proxy_hide_header Pragma;
# instruct browser never to cache this
expires -1;
add_header X-Cache $upstream_cache_status;
proxy_cache_use_stale updating;
proxy_cache_min_uses 1;
# how long should the data be kept in the cache
proxy_cache_valid 200 1s;
# do not consider secure urls as new files
proxy_cache_key $scheme$proxy_host$uri;
}
location ~* /live/.*\.(ts).*$ {
proxy_cache [CACHE_NAME];
proxy_pass [CACHE_PROXY_PASS_STREAM]; # http only
proxy_cache_lock on;
proxy_ignore_headers Cache-Control;
proxy_ignore_headers Set-Cookie;
proxy_ignore_headers X-Accel-Expires;
proxy_ignore_headers Expires;
proxy_hide_header Pragma;
expires 2s;
add_header X-Cache $upstream_cache_status;
proxy_cache_use_stale updating;
proxy_cache_min_uses 1;
proxy_cache_valid 200 10s;
# do not consider secure urls as new files
proxy_cache_key $scheme$proxy_host$uri;
}
# cache configuration for vod (old easycast stations)
location ~* /vod/.*\.(m3u8)$ {
proxy_cache [CACHE_NAME];
proxy_pass [CACHE_PROXY_PASS_STREAM]; # http only
proxy_cache_lock on;
proxy_ignore_headers Cache-Control;
proxy_ignore_headers Set-Cookie;
proxy_ignore_headers X-Accel-Expires;
proxy_ignore_headers Expires;
proxy_hide_header Pragma;
expires 7d;
proxy_cache_valid 200 7d;
add_header X-Cache $upstream_cache_status;
proxy_cache_use_stale updating;
proxy_cache_min_uses 1;
# do not consider secure urls as new files
proxy_cache_key $scheme$proxy_host$uri;
}
location ~* /vod/.*\.(ts)$ {
proxy_cache [CACHE_NAME];
proxy_pass [CACHE_PROXY_PASS_STREAM]; # http only
proxy_cache_lock on;
proxy_ignore_headers Cache-Control;
proxy_ignore_headers Set-Cookie;
proxy_ignore_headers X-Accel-Expires;
proxy_ignore_headers Expires;
proxy_hide_header Pragma;
expires 7d;
add_header X-Cache $upstream_cache_status;
proxy_cache_use_stale updating;
proxy_cache_min_uses 1;
proxy_cache_valid 200 7d;
# do not consider secure urls as new files
proxy_cache_key $scheme$proxy_host$uri;
}
# cache configuration for vod (new easycast stations 06/04/2016)
location ~* \.(m3u8)$ {
proxy_cache [CACHE_NAME];
proxy_pass [CACHE_PROXY_PASS_VOD]; # http only
proxy_cache_lock on;
proxy_ignore_headers Cache-Control;
proxy_ignore_headers Set-Cookie;
proxy_ignore_headers X-Accel-Expires;
proxy_ignore_headers Expires;
proxy_hide_header Pragma;
expires 7d;
proxy_cache_valid 200 7d;
add_header X-Cache $upstream_cache_status;
proxy_cache_use_stale updating;
proxy_cache_min_uses 1;
# do not consider secure urls as new files
proxy_cache_key $scheme$proxy_host$uri;
}
location ~* \.(ts)$ {
proxy_cache [CACHE_NAME];
proxy_pass [CACHE_PROXY_PASS_VOD]; # http only
proxy_cache_lock on;
proxy_ignore_headers Cache-Control;
proxy_ignore_headers Set-Cookie;
proxy_ignore_headers X-Accel-Expires;
proxy_ignore_headers Expires;
proxy_hide_header Pragma;
expires 7d;
add_header X-Cache $upstream_cache_status;
proxy_cache_use_stale updating;
proxy_cache_min_uses 1;
proxy_cache_valid 200 7d;
# do not consider secure urls as new files
proxy_cache_key $scheme$proxy_host$uri;
}
}
server {
listen 443 ssl;
server_name [CLIENT];
ssl_certificate /etc/ssl/ubicast_tv/ubicast_tv_bundle.pem;
ssl_certificate_key /etc/ssl/ubicast_tv/ubicast_tv.key;
location ~* /crossdomain.xml {
alias /var/www/html/crossdomain.xml;
}
# cache configuration for vod (25/07/2016)
location ~* \.(m3u8)$ {
proxy_cache [CACHE_NAME];
proxy_pass [CACHE_PROXY_PASS_VOD];
proxy_cache_lock on;
proxy_ignore_headers Cache-Control;
proxy_ignore_headers Set-Cookie;
proxy_ignore_headers X-Accel-Expires;
proxy_ignore_headers Expires;
proxy_hide_header Pragma;
expires 7d;
proxy_cache_valid 200 7d;
add_header X-Cache $upstream_cache_status;
proxy_cache_use_stale updating;
proxy_cache_min_uses 1;
}
location ~* \.(ts)$ {
proxy_cache [CACHE_NAME];
proxy_pass [CACHE_PROXY_PASS_VOD];
proxy_cache_lock on;
proxy_ignore_headers Cache-Control;
proxy_ignore_headers Set-Cookie;
proxy_ignore_headers X-Accel-Expires;
proxy_ignore_headers Expires;
proxy_hide_header Pragma;
expires 7d;
add_header X-Cache $upstream_cache_status;
proxy_cache_use_stale updating;
proxy_cache_min_uses 1;
proxy_cache_valid 200 7d;
}
}
<!DOCTYPE html> <!DOCTYPE html>
<html> <html xmlns="http://www.w3.org/1999/xhtml">
<head> <head>
<title>Welcome to nginx!</title> <title>UbiCast cache server</title>
<style> <style>
body { html { background: #222; color: #ddd; }
width: 35em; body { margin: 0 auto; max-width: 500px; }
margin: 0 auto; a { color: #5cf; text-decoration: none; }
font-family: Tahoma, Verdana, Arial, sans-serif; a:hover { text-decoration: underline; }
} </style>
</style> </head>
</head> <body>
<body> <h1>UbiCast cache server</h1>
<h1>[CLIENT] nginx cache server</h1> <hr/>
</body> <p>Hosted on server {{ hostname }}.</p>
<br/>
<hr/>
<p>Powered by UbiCast -- <a href="https://www.ubicast.eu">https://www.ubicast.eu</a></p>
</body>
</html> </html>
#!/bin/bash
source /root/envsetup/global-conf.sh
# for munin
DEBIAN_FRONTEND=noninteractive apt-get install -y ubicast-config
File moved
...@@ -61,7 +61,8 @@ campusmanager() { ...@@ -61,7 +61,8 @@ campusmanager() {
cache() { cache() {
python3 /root/envsetup/envsetup.py 81 python3 /root/envsetup/envsetup.py 81
python3 /root/envsetup/envsetup.py 82 python3 /root/envsetup/envsetup.py 82
python3 /root/envsetup/envsetup.py 83 python3 /root/envsetup/envsetup.py 25
python3 /root/envsetup/envsetup.py 26
} }
tests() { tests() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment