caching a webcam
I Recently tried to use a webcam on the internet and it was unusable because too many people were using it.
Taking a peek, it was clear it was simple jpgs being refreshed by client side JS , using the built in webui in the camera itself, the hardware just couldn't handle too many users.
So I setup some urls and cloudfront to cache, and then an nginx proxy which would do the right thing with headers to make the images cache friendly. Then reached out to the webmaster and talked them through what to do
Next step is to consider changing the client JS to not just increment a number in the url, which is ignored by the CDN, but maybe find some other way to cache to you get better than one frame a second.
server {
listen 8888;
access_log /var/log/nginx/cam1.access.log;
error_log /var/log/nginx/cam1.error.log;
server_name cam1.test.com;
location / {
add_header Pragma public;
add_header Cache-Control "public,max-age=1,s-max-age=1";
proxy_pass http://1.2.3.4:120/;
proxy_set_header Host 1.2.3.4;
}
}
server {
listen 8888;
access_log /var/log/nginx/cam2.access.log;
error_log /var/log/nginx/cam2.error.log;
server_name cam2.test.com;
location / {
add_header max-age 1;
add_header s-max-age 1;
add_header Pragma public;
add_header Cache-Control "public";
proxy_pass http://1.2.3.4:121/;
proxy_set_header Host 1.2.3.4;
}
}
server {
listen 8888;
access_log /var/log/nginx/cam3.access.log;
error_log /var/log/nginx/cam3.error.log;
server_name cam3.test.com;
location / {
add_header max-age 1;
add_header s-max-age 1;
add_header Pragma public;
add_header Cache-Control "public";
proxy_pass http://1.2.3.4:122/;
proxy_set_header Host 1.2.3.4;
}
}
Taking a peek, it was clear it was simple jpgs being refreshed by client side JS , using the built in webui in the camera itself, the hardware just couldn't handle too many users.
So I setup some urls and cloudfront to cache, and then an nginx proxy which would do the right thing with headers to make the images cache friendly. Then reached out to the webmaster and talked them through what to do
Next step is to consider changing the client JS to not just increment a number in the url, which is ignored by the CDN, but maybe find some other way to cache to you get better than one frame a second.
server {
listen 8888;
access_log /var/log/nginx/cam1.access.log;
error_log /var/log/nginx/cam1.error.log;
server_name cam1.test.com;
location / {
add_header Pragma public;
add_header Cache-Control "public,max-age=1,s-max-age=1";
proxy_pass http://1.2.3.4:120/;
proxy_set_header Host 1.2.3.4;
}
}
server {
listen 8888;
access_log /var/log/nginx/cam2.access.log;
error_log /var/log/nginx/cam2.error.log;
server_name cam2.test.com;
location / {
add_header max-age 1;
add_header s-max-age 1;
add_header Pragma public;
add_header Cache-Control "public";
proxy_pass http://1.2.3.4:121/;
proxy_set_header Host 1.2.3.4;
}
}
server {
listen 8888;
access_log /var/log/nginx/cam3.access.log;
error_log /var/log/nginx/cam3.error.log;
server_name cam3.test.com;
location / {
add_header max-age 1;
add_header s-max-age 1;
add_header Pragma public;
add_header Cache-Control "public";
proxy_pass http://1.2.3.4:122/;
proxy_set_header Host 1.2.3.4;
}
}
Comments
Jyoti 목포 출장마사지 Gaming 남원 출장마사지 is 강원도 출장안마 a supplier of integrated gaming solutions to the industry of online gambling, including 의정부 출장안마 online slots, live dealer and more. 태백 출장안마