1. 对根目录下的静态资源代理
Nginx代理nginx.conf配置——反向代理
2. 目录代理
如果需要将资源代理到不同的目录下,则在nginx.conf中的server节点下进行如下配置:
location /image {
root /opt/cache;
}
location vedio {
root /opt/cache;
}
修改后,重新加载nginx配置即可,nginx部分命令如下:
# 检查配置
nginx -t
# 重载配置
nginx -s reload
# 关闭
nginx -s quit
# 启动
nginx -s start
3. 代理指定路径下的静态资源
在server中添加如下配置(示例listen端口为80)
location ~ /video/.*\.(mp4)?$ {
expires -1;
# 匹配结果示例:opt/cache/video/demo.mp4
root /opt/cache;
}
访问:localhost/video/demo.mp4即可访问
文章介绍了如何使用Nginx进行静态资源的代理,包括对根目录的代理、不同目录的代理以及指定路径下静态资源(如mp4文件)的代理方法。配置涉及location指令、root指令以及重载配置的nginx命令。
4690

被折叠的 条评论
为什么被折叠?



