nginx+tomcat+二级域名静态文件分离支持mp4视频播放配置实例
二级域名配置
在/etc/nginx/conf.d/目录下配置二级域名同名的conf文件,路径改成对应的即可
statics.xxxxx.com.conf
server {
listen ;
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 ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
expires 30d;
}
location ~ .*\.(js|css)?$ {
expires 7d;
}
location /video/ {
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 http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
}
------------------------------
主域名转发到tomcat配置,端口号自己改:
server {
listen ;
server_name localhost; location / {
client_max_body_size 10m;
index index.html index.htm index.jsp;
proxy_set_header Host $host;
proxy_pass_header User-Agent;
proxy_pass http://localhost:8089/; } error_page /.html;
location = /40x.html {
} error_page /50x.html;
location = /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