打开编辑 nginx-1.12.1\conf\nginx.conf
文件 在sever中添加 location /image
块儿即可
server {
listen 80;
server_name localhost;
location /image {
root D:/pyworkspace/TGDB/images/;
}
浏览器访问http://127.0.0.1/image/test.jpg
就会加载 D:/pyworkspace/TGDB/images/image/test.jpg
这张图
加载静态文件的两种方式
root
root加载原理:url拼接root中的目录加载资源
step1 # 拿到url中的 image/test.jpg
step2 # 用root中的D:/pyworkspace/TGDB/images/
+image/test.jpg
alias
alias加载原理:把location中出现在alias中的字符串去掉 ,拼接到alias中