最近不知道怎么了,我的下载站就一直没法加载静态文件,然后我去看了一下浏览器开发工具的输出,全部都是无法加载(请求超时),因为这些文件都在官方的CDN上所以我也没法判断具体出现了什么问题,我研究了一下,使用学校的网络访问这个CDN根本就上不去,一直是TimeOut而且没有任何来自对方服务器的响应,但是使用我的香港服务器curl一下却发现能通,真的是日了dog了,然后我尝试把所有加载失败的文件全部使用wget下载到我专门存放静态文件的站点上,全部下载成功了:
[root@linxi fastgithub]# wget https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.13.1/css/all.min.css
--2022-05-27 15:56:38-- https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.13.1/css/all.min.css
Resolving cdn.jsdelivr.net (cdn.jsdelivr.net)... 151.101.77.229, 2a04:4e42:12::485
Connecting to cdn.jsdelivr.net (cdn.jsdelivr.net)|151.101.77.229|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 58935 (58K) [text/css]
Saving to: ‘all.min.css’
all.min.css 100%[=================================================>] 57.55K --.-KB/s in 0.001s
2022-05-27 15:56:38 (40.0 MB/s) - ‘all.min.css’ saved [58935/58935]
[root@linxi fastgithub]# wget https://cdn.jsdelivr.net/npm/bootstrap@4.5.0/dist/css/bootstrap.min.css
--2022-05-27 15:56:50-- https://cdn.jsdelivr.net/npm/bootstrap@4.5.0/dist/css/bootstrap.min.css
Resolving cdn.jsdelivr.net (cdn.jsdelivr.net)... 151.101.77.229, 2a04:4e42:12::485
Connecting to cdn.jsdelivr.net (cdn.jsdelivr.net)|151.101.77.229|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 160403 (157K) [text/css]
Saving to: ‘bootstrap.min.css’
bootstrap.min.css 100%[=================================================>] 156.64K --.-KB/s in 0.002s
2022-05-27 15:56:50 (69.4 MB/s) - ‘bootstrap.min.css’ saved [160403/160403]
[root@linxi fastgithub]# wget https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js
--2022-05-27 15:57:03-- https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js
Resolving cdn.jsdelivr.net (cdn.jsdelivr.net)... 151.101.77.229, 2a04:4e42:12::485
Connecting to cdn.jsdelivr.net (cdn.jsdelivr.net)|151.101.77.229|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 89476 (87K) [application/javascript]
Saving to: ‘jquery.min.js’
jquery.min.js 100%[=================================================>] 87.38K --.-KB/s in 0.001s
2022-05-27 15:57:03 (71.2 MB/s) - ‘jquery.min.js’ saved [89476/89476]
[root@linxi fastgithub]# wget https://cdn.jsdelivr.net/npm/jquery-file-download@1.4.6/src/Scripts/jquery.fileDownload.js--2022-05-27 15:57:19-- https://cdn.jsdelivr.net/npm/jquery-file-download@1.4.6/src/Scripts/jquery.fileDownload.js
Resolving cdn.jsdelivr.net (cdn.jsdelivr.net)... 151.101.77.229, 2a04:4e42:12::485
Connecting to cdn.jsdelivr.net (cdn.jsdelivr.net)|151.101.77.229|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 19606 (19K) [application/javascript]
Saving to: ‘jquery.fileDownload.js’
jquery.fileDownload.js 100%[=================================================>] 19.15K --.-KB/s in 0s
2022-05-27 15:57:20 (105 MB/s) - ‘jquery.fileDownload.js’ saved [19606/19606]
[root@linxi fastgithub]# wget https://cdn.jsdelivr.net/npm/bootstrap@4.5.0/dist/js/bootstrap.bundle.min.js
--2022-05-27 15:57:29-- https://cdn.jsdelivr.net/npm/bootstrap@4.5.0/dist/js/bootstrap.bundle.min.js
Resolving cdn.jsdelivr.net (cdn.jsdelivr.net)... 151.101.77.229, 2a04:4e42:12::485
Connecting to cdn.jsdelivr.net (cdn.jsdelivr.net)|151.101.77.229|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 81084 (79K) [application/javascript]
Saving to: ‘bootstrap.bundle.min.js’
bootstrap.bundle.min.js 100%[=================================================>] 79.18K --.-KB/s in 0.001s
2022-05-27 15:57:30 (68.5 MB/s) - ‘bootstrap.bundle.min.js’ saved [81084/81084]
[root@linxi fastgithub]# wget https://cdn.jsdelivr.net/npm/clipboard@2.0.6/dist/clipboard.min.js
--2022-05-27 15:57:40-- https://cdn.jsdelivr.net/npm/clipboard@2.0.6/dist/clipboard.min.js
Resolving cdn.jsdelivr.net (cdn.jsdelivr.net)... 151.101.77.229, 2a04:4e42:12::485
Connecting to cdn.jsdelivr.net (cdn.jsdelivr.net)|151.101.77.229|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 10453 (10K) [application/javascript]
Saving to: ‘clipboard.min.js’
clipboard.min.js 100%[=================================================>] 10.21K --.-KB/s in 0s
2022-05-27 15:57:40 (92.3 MB/s) - ‘clipboard.min.js’ saved [10453/10453]
[root@linxi fastgithub]# wget https://cdn.jsdelivr.net/npm/jquery-file-download@1.4.6/src/Scripts/jquery.fileDownload.js--2022-05-27 15:57:53-- https://cdn.jsdelivr.net/npm/jquery-file-download@1.4.6/src/Scripts/jquery.fileDownload.js
Resolving cdn.jsdelivr.net (cdn.jsdelivr.net)... 151.101.77.229, 2a04:4e42:12::485
Connecting to cdn.jsdelivr.net (cdn.jsdelivr.net)|151.101.77.229|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 19606 (19K) [application/javascript]
Saving to: ‘jquery.fileDownload.js.1’
jquery.fileDownload.js.1 100%[=================================================>] 19.15K --.-KB/s in 0s
2022-05-27 15:57:53 (107 MB/s) - ‘jquery.fileDownload.js.1’ saved [19606/19606]
[root@linxi fastgithub]# cd ..
[root@linxi static.linxi.info]# cd webfonts/
[root@linxi webfonts]# wget https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/webfonts/fa-solid-900.woff2
--2022-05-27 16:03:19-- https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/webfonts/fa-solid-900.woff2
Resolving cdnjs.cloudflare.com (cdnjs.cloudflare.com)... 104.17.24.14, 104.17.25.14, 2606:4700::6811:180e, ...
Connecting to cdnjs.cloudflare.com (cdnjs.cloudflare.com)|104.17.24.14|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 80148 (78K) [application/octet-stream]
Saving to: ‘fa-solid-900.woff2’
fa-solid-900.woff2 100%[=================================================>] 78.27K --.-KB/s in 0.002s
2022-05-27 16:03:20 (44.3 MB/s) - ‘fa-solid-900.woff2’ saved [80148/80148]
[root@linxi webfonts]# wget https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/webfonts/fa-solid-900.woff
--2022-05-27 16:04:02-- https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/webfonts/fa-solid-900.woff
Resolving cdnjs.cloudflare.com (cdnjs.cloudflare.com)... 104.17.25.14, 104.17.24.14, 2606:4700::6811:190e, ...
Connecting to cdnjs.cloudflare.com (cdnjs.cloudflare.com)|104.17.25.14|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/octet-stream]
Saving to: ‘fa-solid-900.woff’
fa-solid-900.woff [ <=> ] 101.57K --.-KB/s in 0.002s
2022-05-27 16:04:02 (54.1 MB/s) - ‘fa-solid-900.woff’ saved [104004]
[root@linxi webfonts]# wget https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/webfonts/fa-solid-900.ttf
--2022-05-27 16:04:32-- https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/webfonts/fa-solid-900.ttf
Resolving cdnjs.cloudflare.com (cdnjs.cloudflare.com)... 104.17.25.14, 104.17.24.14, 2606:4700::6811:180e, ...
Connecting to cdnjs.cloudflare.com (cdnjs.cloudflare.com)|104.17.25.14|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/octet-stream]
Saving to: ‘fa-solid-900.ttf’
fa-solid-900.ttf [ <=> ] 199.20K --.-KB/s in 0.004s
2022-05-27 16:04:32 (54.4 MB/s) - ‘fa-solid-900.ttf’ saved [203980]
但是我一加载网站发现字体全部无法加载:
全部字体报错:
已拦截跨源请求:同源策略禁止读取位于 https://static.linxi.info/webfonts/fa-solid-900.woff2 的远程资源。(原因:CORS 头 'Access-Control-Allow-Origin' 不匹配 'origin-list')。
然后我去看了一下mozilla官方的开发文档发现了以下解决方法:
add_header 'Access-Control-Allow-Origin' '你的网站域名';
我添加到了nginx的站点配置文件中,但是似乎并没有其任何作用,仍然报错,我又看了一遍文档,又发现了以下内容:
我又把配置文件中的"add_header 'Access-Control-Allow-Origin' 'https://api.service.linxi.info';"修改为"add_header 'Access-Control-Allow-Origin' '*';"
add_header 'Access-Control-Allow-Origin' '*';
刷新网站,问题成功解决!