Nginx代理nginx.conf配置——nginx对静态文件代理

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即可访问

猜你喜欢

转载自blog.csdn.net/pp_lan/article/details/131811477