Get the App
SLTechnology News&Howtos  ›  Servers  › 

The solution to the invalid cross-domain setting Access-Control-Allow-Origin of Nginx

Shulou Source: shulou.com Published: 2022-06-02 03:17:16 10月25日 Update

Nginx version 1.11.3

Using the following configuration, the verification is invalid and the cross-domain problem still exists

Add_header 'Access-Control-Allow-Origin'' *'; add_header 'Access-Control-Allow-Credentials'' true';add_header 'Access-Control-Allow-Methods'' GET,POST'

Use the following configuration to take effect.

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';}

Summary

The above is the whole content of this article. I hope the content of this article has a certain reference and learning value for everyone's study or work. Thank you for your support. If you want to know more about it, please see the relevant links below.

Tags: Content learning configuration value that is more versions articles links questions references work support verification methods Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology NVidia Microsoft OPPO Reno vpn