Nginx - linux 静态资源配置与防盗链
- 图片服务器
- 路径配置
- location 匹配规则最好不要与访问路径相同,否则会追加在路径后面,当作访问地址
- root 与 alias root是真实的路径,而alias的最后一层会被 location 访问规则代替
- 所指定的路径注意访问权限&注意nginx运行时使用的身份
#------------------------------------------------------------------------------------------------------
# 静态资源配置
server {
listen 90;
server_name localhost;
#防盗链
include valid_referers.conf;
location /static {
#路径配置
#location 匹配规则最好不要与访问路径相同,否则会追加在路径后面,当作访问地址
#root 与 alias root是真实的路径,而alias的最后一层会被 location 访问规则代替
#所指定的路径注意访问权限&注意nginx运行时使用的身份
alias /home/chenyb/nginx_static;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
#-----------------------------------------------------------------------------------------------------
![](https://i-blog.csdnimg.cn/blog_migrate/ce1a52cd38386e8b44556c2de0ef16f8.png)
- 静动分离-web静态项目
- 在http模块中配置,项目路径/home/chenyb/,index.html首页在这个/home/chenyb/下
- 注意将内部引用以及配置的路径改为nginx发布后的实际路径
server {
listen 9090;
server_name localhost;
location /index {
#路径配置
alias /home/chenyb/foodie-shop;
index index.html index.htm;
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/e7abece1d07fb992779e103740876510.png)
- 防盗链( valid_referers.conf)
#对源站点验证
#valid_referers *.chenyb.com;
#测试用所以没有做限制
valid_referers *;
#非法引入会进入下方判断
if ($invalid_referer) {
return 404;
}