1.root与alias
root 路径完全匹配访问 用户访问:url:port/im/home下的资源
location /im {
root /home
}
alias 是给一个路径起别名 用户访问:url:port/hello/{alias设置的目录}
location /hello{
alias /home
}
2.location的匹配规则
空格:默认匹配,普通匹配
location / {
root /home:
}
=:精确匹配
location = /im/img/1.png {
root /home:
}
~*:匹配正则表达式,不区分大小写
符合图片的显示
location ~\.(gif|jpg|png|jpeg) {
root /home:
}
3.跨域配置
#允许跨域请求的域,#代表所有
add_header ’Access-Control-Allow-Origin’ *;
#允许带上cookie请求
add_header ’Access-Control-Allow-Credentials’ ’true’;
#允许请求的方法,比如 GET/POST/PUT/DELETE
add_header ’Access-Control-Allow-Methods’ *;
#允许请求的header
add_header ’Access-Control-Allow-Headers’ *;
4.防盗链配置
#对源站点验证
valid_refreres *.im.com:
#非法引入会进入一下判断
if(¥invalid_referer){
return 404;
}