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 ~ .*\.(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 80; 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 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /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