鍍金池/ 問答/Linux  HTML/ 關(guān)于access control allow origin header is

關(guān)于access control allow origin header is present錯誤 nginx

準(zhǔn)備部署一個本地系統(tǒng),然后請求后端是使用https,結(jié)果發(fā)現(xiàn)登錄的接口沒問題,提交數(shù)據(jù)的接口就出問題了,
問題:
Failed to load resource: the server responded with a status of 500 ()
input.html:1 Failed to load https://127.0.0.1/acquisition...: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1' is therefore not allowed access. The response had HTTP status code 500.

使用了jquery 提交;
后臺 nginx.conf 部分 配置:


# Begin HTTPS Server
server {

       
       add_header Access-Control-Allow-Origin "http://127.0.0.1";
       #add_header Access-Control-Allow-Origin *;
       add_header Access-Control-Allow-Credentials true;
       add_header Access-Control-Allow-Headers "x-requested-with,Authorization";
       add_header Access-Control-Allow-Methods *;
   }
   
   # return 404 for all other php files not matching the front controller
   # this prevents access to other php files you don't want to be accessible.
   location ~ \.php$ {
     return 404;
   }

   error_log project_error.log;
   access_log project_access.log;
} # End HTTPS Server
}

jquery已經(jīng)在請求頭加上 withCredential, crossDomain等字段的;在未部署成localhost本機訪問之前都是可用的

請求方法:

$.ajax({
    type:"post",
    url: "https://127.0.0.1/post",
    data: data,
    success: function(){},
    error: function(){}
})

瀏覽器的信息顯示如下:
圖片描述

回答
編輯回答
女流氓

你這是跨域問題。請搜索CORS。
需要服務(wù)器端邏輯中添加特殊的響應(yīng)頭,允許從其它網(wǎng)站(即跨域)往本服務(wù)器發(fā)送Ajax請求。
客戶端(調(diào)用端)是無法解決的。

2018年9月5日 02:15