静态文件
即实现nginx代理指向静态文件,动静分离
主要配置如下:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
server {
listen 80;
server_name localhost;
location /images {
root /Users/jun/data;
}
location / {
root /Users/jun/data/www;
index index.html index.htm;
}
}
include servers/*;
}
http://localhost/images/jie.png
的请求会匹配上面的location,返回本地/Users/jun/data/images/jie.png的图片,
http://localhost/
的请求会匹配到下面的location,然后返回本地/Users/jun/data/www/下面的index.html文件。
开始一直搞不懂文件匹配规则,其实就是匹配到相应的location后,把请求url拼接到root的参数后去本地文件系统中查找,如刚才http://localhost/
请求,返回/Users/jun/data
+ /
即/Users/jun/data/
下的index.html(缺省文件),对于http://localhost/images/jie.png
请求 就返回/Users/jun/data/www
+ /images/jie.png
即服务器本地/Users/jun/data/images/jie.png
的图片。
至于匹配哪