我創建了一個網站ideahubbd.com,其中有兩個部分,稱為“服務”和“想法”是動態資料。來自http://api.ideahubbd.com/ourservice.json & http://api.ideahubbd.com/ideas.json
在我的專案中,當我在 localhost 中運行它時,它會從 API 中獲取這些資料,但是當我將 reactbuild檔案夾上傳到服務器時,它并沒有獲取這些資料。
有什么我想念的嗎?是API的問題嗎?
在 api.ideahubbd.com 的組態檔的 nginx 中我有這個配置
server {
# Binds the TCP port 80.
listen 80;
# Root directory used to search for a file
root /var/www/html/ideahubbd_static_api;
# Defines the file to use as index page
index index.html index.htm;
# Defines the domain or subdomain name.
# If no server_name is defined in a server block then
# Nginx uses the 'empty' name
server_name api.ideahubbd.com;
location / {
# Return a 404 error for instances when the server receives
# requests for untraceable files and directories.
try_files $uri $uri/ =404;
add_header Access-Control-Allow-Origin *;
}
}
有什么我想念的嗎!
uj5u.com熱心網友回復:
以下鏈接解釋了此問題的原因以及如何解決它。總之,我想告訴你,因為你呼叫的服務沒有ssl證書,必須呼叫https,所以在瀏覽器控制臺很容易看到錯誤
如何修復“通過 HTTPS 加載不安全的內容,但請求了不安全的資源”
uj5u.com熱心網友回復:
在 StackOverflow 上搜索后,我找到了答案,有兩種方法可以解決它。第一件事是將 SSL 添加到 API URL。
第二件事最初由@buzatto在這里回答。
“這與在您的網站加載 https 時以 http 提供 api 的事實有關,因此瀏覽器會阻止請求。
由于您無法控制 3rd 方 api,因此您可以解決添加元標記的問題<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">“
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/490079.html
標籤:javascript 反应 nginx
上一篇:通過shell腳本在后臺運行帶有docker容器的exec時和平的“dockerstop”
下一篇:在公共子資源后面映射本地應用程式
