1. apache静态资源跨域访问找到apache配置文件httpd.conf找到这行#LoadModule headers_module modules/mod_headers.so把#注释符去掉LoadModule headers_module modules/mod_headers.so目的是开启apache头信息自定义模块在独立主机配置文件中新增headerHeader set Access-Control-Allow-Origin *例如: <VirtualHost *:88> ServerAdmin admin@example.com DocumentRoot "****************" ServerName www.jb51.com Header set Access-Control-Allow-Origin * ErrorLog "***********" CustomLog "****************************" common<Directory "**************"> SetOutputFilter DEFLATE Options FollowSymLinks ExecCGI Require all granted AllowOverride All Order allow,deny Allow from all DirectoryIndex index.html index.php</Directory></VirtualHost>ApacheCopy意思是对这个域名的资源进行访问时,添加一个头信息重启apacheservice httpd restart2. nginx静态资源容许跨域访问同理 找到相应域名配置文件在server模块中添加配置:add_header ‘Access-Control-Allow-Origin' ‘*'; server { listen 80; add_header 'Access-Control-Allow-Origin' '*'; location /Roboto/ { root /home/images; autoindex on; } }nginx重载./nginx -s reload经过以上方法配置完后,再次跨域访问静态资源就没有问题了以上既是nginx/apache静态资源容许跨域访问解决方法