主頁 > 知識庫 > 解決nginx/apache靜態(tài)資源跨域訪問問題詳解

解決nginx/apache靜態(tài)資源跨域訪問問題詳解

熱門標(biāo)簽:廣東如何申請400電話 燃?xì)夤芫€地圖標(biāo)注顏色 哈爾濱400電話去哪辦理 寧波400電話辦理對企業(yè)的意義 400電話申請要什么條件 話術(shù)外呼系統(tǒng) i智能電話機(jī)器人yeta 北京人工外呼系統(tǒng)廠家 西柏坡地圖標(biāo)注

1. apache靜態(tài)資源跨域訪問

找到apache配置文件httpd.conf

找到這行

#LoadModule headers_module modules/mod_headers.so

把#注釋符去掉

LoadModule headers_module modules/mod_headers.so

目的是開啟apache頭信息自定義模塊

在獨(dú)立主機(jī)配置文件中新增header

Header 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

意思是對這個(gè)域名的資源進(jìn)行訪問時(shí),添加一個(gè)頭信息

重啟apache

service httpd restart

2. nginx靜態(tài)資源允許跨域訪問

同理 找到相應(yīng)域名配置文件

在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

通過以上方法配置完后,再次跨域訪問靜態(tài)資源就沒有問題了

以上既是nginx/apache靜態(tài)資源允許跨域訪問解決方法

標(biāo)簽:襄陽 西藏 阜陽 珠海 開封 湘潭 巴中 張家口

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《解決nginx/apache靜態(tài)資源跨域訪問問題詳解》,本文關(guān)鍵詞  解決,nginx,apache,靜態(tài),資源,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《解決nginx/apache靜態(tài)資源跨域訪問問題詳解》相關(guān)的同類信息!
  • 本頁收集關(guān)于解決nginx/apache靜態(tài)資源跨域訪問問題詳解的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章