搭好fastdfs以后,正常访问浏览器没问题,但是前端获取的时候会出现跨越访问。因为访问fastdfs的图片的时候是用Nginx访问的,nginx当中要配置跨域访问,前端才能正常获取图片。
一定要在location里面配置如下2行
add_header ‘Access-Control-Allow-Origin’ ‘*’;
add_header ‘Access-Control-Allow-Credentials’ ‘true’;
worker_processes 1;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
#location /group1/M00 {
#alias /fastdfs_log/fastdfs/file/data;
#}
location ~/group([0-9])/M00 {
ngx_fastdfs_module;
#加上如下2行解决前端获取文件跨域访问的问题
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
}
}
}



