首页
点滴
Nginx 配置动静分离
#### 本例接着上一章负载均衡的基础上修改 示例效果: 当请求是以 /static/ 开头的我们则认为它是访问静态资源,这个时候我们就不需要去请求 Tomcat 了,直接在 Nginx 下处理 。  #### 配置 Nginx 动静分离 编辑 nginx 目录下的 /conf 目录下的 nginx.conf 配置文件。添加一个 location 模块。 `/static/` 表示 匹配请求中的 /static/ 请求将会进入这里处理, `root /mydata/;` 表示在服务器根目录中 /mydata/目录里面找到/static 目录; `autoindex on;` 表示列出请求/static/中的目录 ``` location /static/ { root /mydata/; autoindex on; } ```  #### 新建静态资源目录 在服务器根目录中新建 /mydata/static/images/ 目录,里面放一张img01.jpg的图片 #### 重启Nginx,测试访问 http://192.168.1.12/static/images/img01.jpg  测试访问正常
博客分类
源码解析 (1)
多线程 (5)
Linux (7)
Java (9)
Docker (7)
SpringBoot (14)
微服务 (1)
Redis (15)
MySQL (7)
VMware (3)
Nginx (12)
MyBatis (2)
Git (7)
RabbitMQ (1)
工具类 (12)
友情链接
layui
© 2020-2021 www.chenhuazhan.com All Rights Reserved 备案号:
桂ICP备17004487号-1