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 ~ .*\.(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
大自然,飘然的风,QQ群: python技术交流群:453879716,人工智能深度学习群:251088643
golang技术交流群:316397059,vuejs技术交流群:458915921 囤币一族:621258209,有兴趣的可以加入
微信公众号: 心禅道(xinchandao)投资论道
golang技术交流群:316397059,vuejs技术交流群:458915921 囤币一族:621258209,有兴趣的可以加入
微信公众号: 心禅道(xinchandao)投资论道
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?