zoukankan      html  css  js  c++  java
  • nginx+tomcat+二级域名静态文件分离支持mp4视频播放配置实例

    nginx+tomcat+二级域名静态文件分离支持mp4视频播放配置实例

    二级域名配置

    在/etc/nginx/conf.d/目录下配置二级域名同名的conf文件,路径改成对应的即可
    statics.xxxxx.com.conf
    复制代码
    server {
        listen 80;
        server_name    statics.xxxxx.com ;
        access_log  /var/log/nginx/access_statics.xxxxx.com.log;
        error_log  /var/log/nginx/error_statics.xxxxx.com.log;
        root /home/www/statics;
        index index.html index.htm;
    
    location </span>~ .*.(gif|jpg|jpeg|png|bmp|swf|flv|<span style="color: #000000;">ico)$ {
        expires 30d;
        }
    location </span>~ .*.(js|css)?<span style="color: #000000;">$ {
        expires 7d;
    }
    location </span>/video/<span style="color: #000000;"> {
        mp4;
        mp4_buffer_size       4m;
        mp4_max_buffer_size   10m;
    }
    

    }

    复制代码

    支持mp4视频格式在 location /video/ 这个配置里。

    ---------------------------------

    nginx配置:

    复制代码
    # For more information on configuration, see:
    #   * Official English Documentation: http://nginx.org/en/docs/
    #   * Official Russian Documentation: http://nginx.org/ru/docs/
    
    user nginx;
    worker_processes auto;
    error_log /var/log/nginx/error.log;
    pid /var/run/nginx.pid;
    

    Load dynamic modules. See /usr/share/nginx/README.dynamic.

    include /usr/share/nginx/modules/*.conf;

    events {
    worker_connections 1024;
    }

    http {
    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;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;
    
    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;
    
    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See </span><span style="color: #008000; text-decoration: underline;">http://nginx.org/en/docs/ngx_core_module.html</span><span style="color: #008000;">#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;
    

    }

    复制代码

    ------------------------------

    主域名转发到tomcat配置,端口号自己改:

    复制代码
    server {
        listen       80;
        server_name  localhost;
    
    location </span>/<span style="color: #000000;"> {
        client_max_body_size    10m;
        index  index.html index.htm index.jsp;
        proxy_set_header Host $host;
        proxy_pass_header User</span>-<span style="color: #000000;">Agent;
        proxy_pass http:</span><span style="color: #008000;">//</span><span style="color: #008000;">localhost:8089/;</span>
    
    }
    error_page </span><span style="color: #800080;">404</span> /<span style="color: #800080;">404</span><span style="color: #000000;">.html;
        location </span>= /<span style="color: #000000;">40x.html {
    }
    
    error_page </span><span style="color: #800080;">500</span> <span style="color: #800080;">502</span> <span style="color: #800080;">503</span> <span style="color: #800080;">504</span> /<span style="color: #000000;">50x.html;
        location </span>= /<span style="color: #000000;">50x.html {
    }
    

    }

    复制代码

    测试视频html,视频文件要放在同一目录下:

    复制代码
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>测试视频</title>
    </head>
    <body>
    <video width="520" height="540" controls autoplay="autoplay">
      <source src="test.mp4" type="video/mp4" >
    </video>
    </body>
    </html>
    复制代码

    -------------------------------
    nginx+tomcat转发的,域名是在那里配置的了?
    在tomcat的server.xml里面也是用<Host name="localhost" 没看到配置域名的
    listen 80;
    server_name localhost;
    localhost就是域名
    相当于这个是默认主机 所有解析到这台的 都会跑到这里去了
    相当于所有域名只要解析到这台ip来 就会直接跑到这里来了

    ping下看解析 和你现在的云主机是同个ip?
    是同一IP,那就是没走slb

  • 相关阅读:
    六种排序
    洛谷 P1879 [USACO06NOV]玉米田Corn Fields
    [USACO06NOV]玉米田Corn Fields
    c++位运算符 | & ^ ~ && ||,补码,反码
    Blockade(Bzoj1123)
    割点(Tarjan算法)【转载】
    子串
    生命是什么
    怎样说话才打动人
    自控力
  • 原文地址:https://www.cnblogs.com/jpfss/p/9284937.html
Copyright © 2011-2022 走看看