nginx/apache靜態資源跨域訪問問題詳解

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靜態資源容許跨域訪問解決方法
相關文章
相關標籤/搜索