Nginx跨域設(shè)置Access-Control-Allow-Origin無效的解決辦法
nginx 版本 1.11.3
使用大家說的以下配置,驗(yàn)證無效,跨域問題仍然存在
add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Credentials' 'true'; add_header 'Access-Control-Allow-Methods' 'GET,POST';
使用以下配置,生效。
if ($request_method = 'OPTIONS') { add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; add_header 'Access-Control-Max-Age' 1728000; add_header 'Content-Type' 'text/plain charset=UTF-8'; add_header 'Content-Length' 0; return 204; } if ($request_method = 'POST') { add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; } if ($request_method = 'GET') { add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; }
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請(qǐng)查看下面相關(guān)鏈接
相關(guān)文章
Nginx實(shí)現(xiàn)ChatGPT?API代理步驟
這篇文章主要為大家介紹了Nginx實(shí)現(xiàn)ChatGPT?API代理步驟詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-05-05nginx代理服務(wù)器配置雙向證書驗(yàn)證的方法
今天小編就為大家分享一篇關(guān)于nginx代理服務(wù)器配置雙向證書驗(yàn)證的方法,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2019-02-02nginx配置多個(gè)前端項(xiàng)目實(shí)現(xiàn)步驟
本文主要介紹了nginx配置多個(gè)前端項(xiàng)目實(shí)現(xiàn)步驟,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-03-03nginx配置中$http_host、$host、$host:$proxy_port和$host:$server_por
nginx為了實(shí)現(xiàn)反向代理的需求而增加了一個(gè)ngx_http_proxy_module模塊,其中proxy_set_header指令就是該模塊需要讀取的配置文件,這篇文章主要介紹了nginx配置中$http_host、$host、$host:$proxy_port和$host:$server_port區(qū)別,需要的朋友可以參考下2024-03-03nginx鏡像構(gòu)建的知識(shí)點(diǎn)及方法步驟詳解
這篇文章主要為大家介紹了nginx鏡像構(gòu)建的知識(shí)點(diǎn)詳解,<BR>有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-08-08nginx的限流和網(wǎng)關(guān)gatway限流詳解
這篇文章主要介紹了nginx的限流和網(wǎng)關(guān)gatway限流,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-08-08