nginx+uwsgi+webpy+flvjs搭建视频站

目录

1. nginx install

2. uwsgi install

3. webpy

4. nginx配置

5. webpy配置

6. 证书文件生成

7. 启动uwsgi

8. 重启nginx并把nginx打开自动启动

9. 浏览器访问127.0.0.1:8888 即可打开视频站


1. nginx install

centos网络安装:yum install -y nginx

debian网络安装:apt-get install -y nginx

离线安装:点击打开链接

rpm -ivh nginx-1.14.0-1.el7_4.ngx.x86_64.rpm

2. uwsgi install

yum install -y uwsgi uwsgi-plugin-common uwsgi-plugin-python

离线:点击打开链接

uwsgi-2.0.16-1.el7.x86_64
uwsgi-plugin-common-2.0.16-1.el7.x86_64

uwsgi-plugin-python-2.0.16-1.el7.x86_64

3. webpy

可以用wget网络下载。没网使用离线包也可以

我用的版本是web.py-0.38.tar.gz

进入代码目录后 python setup.py 安装即可

4. nginx配置

user  root;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    client_max_body_size 20G;#不加这个上传大文件会报错
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
	
    server {
        listen 8888 ssl;#我使用了https,端口不能用80否则一直打开nginx的默认网页
        ssl_certificate /etc/nginx/ssl/host.cert;#证书文件全路径,也可以只写文件名则路径为nginx配置文件所在路径/etc/nginx
        ssl_certificate_key /etc/nginx/ssl/host.key;
        #所有请求除了static下的静态文件,全部转发给webpy
        location / {
            include uwsgi_params;
            uwsgi_pass 127.0.0.1:3031;
            #root /root/forum-master/forum-master1;
            #limit_rate_after 1m;
            #limit_rate 100K;
            #index index.html index.htm;
            #uwsgi_param UWSGI_CHDIR /root/forum-master/forum-master1;
            #uwsgi_param UWSGI_SCRIPT forum;
        }
        location /static/ {
            root /root/forum-master/forum-master1;
        }
    }
}

5. webpy配置

webpy使用https,在代码中加入:

from web.wsgiserver import CherryPyWSGIServer
CherryPyWSGIServer.ssl_certificate='static/host.cert'
CherryPyWSGIServer.ssl_private_key='static/host.key'

6. 证书文件生成

openssl genrsa 1024 > host.key
chmod 400 host.key
openssl req -new -x509 -nodes -sha1 -days 365 -key host.key -out host.cert

7. 启动uwsgi

uwsgi --socket :3031 --plugin python --chdir /home/kuangnuzhiren/forum-master/ -w forum --enable-threads

监听tcp端口3031,启用python插件(因为webpy),运行目录,运行的python文件入口,enable多线程

为什么要用nginx+webpy?原因是在测试时发现单纯使用webpy播放大视频文件时会中断,因此对静态文件用nginx来处理

8. 重启nginx并把nginx打开自动启动

service nginx restart
systemctl enable nginx

9. 浏览器访问127.0.0.1:8888 即可打开视频站

前端示例代码:

$def with (post, comment_lis)
<script src="/static/js/lib/flv.min.js"></script>
	<tr>
		<td><p><video id="videoElement$post['filename']" width="320" height="240" controls autostart="off" loop>Your browser does not support the video tag.</video></p></td>
	</tr>
	<script>
		if (flvjs.isSupported()) {
			var videoElement=document.getElementById("videoElement$post['filename']");
			var flvPlayer=flvjs.createPlayer({type:'mp4',url:"$post['filename']"});
			flvPlayer.attachMediaElement(videoElement);
			flvPlayer.load();
			//flvPlayer.play();
		}
	</script>

 

 

 

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

noodle_bear

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值