webman做为API服务,前端使用VUE,部署的时候使用Nginx代理API服务,有些资源图片是通过后台上传的,路径为 /app/admin/upload/img/xxx.png
部署使用宝塔添加站点,类型选为Static,其中 URL rewrite 配置如下
# 真实IP
set_real_ip_from 0.0.0.0/0;
real_ip_header X-Forwarded-For;
# API接口
location /public/api {
proxy_pass http://127.0.0.1:8888;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /private/api {
proxy_pass http://127.0.0.1:8888;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
# 静态资源
location /app/admin {
proxy_pass http://127.0.0.1:8888;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /upload {
proxy_pass http://127.0.0.1:8888;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
这时如果不注释 Config 配置中的
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
error_log /dev/null;
access_log off;
}
location ~ .*\.(js|css)?$
{
expires 12h;
error_log /dev/null;
access_log off;
}
访问图片就404,注释后才能正常访问图片
找了一些相关资料都没有明白其中的问题,烦请大佬解答一下
nginx的root指令
root /www/wwwroot/XXXXX/public;
nginx 匹配优先级的问题,
location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
error_log /dev/null;
access_log off;
}这个优先级比location /{
}高,匹配到前面就匹配不到后面了,静态资源代理可使用 location ^~ /upload {
},提高优先级