Solution to invalid Nginx cross-domain setting Access-Control-Allow-Origin

Solution to invalid Nginx cross-domain setting Access-Control-Allow-Origin

nginx version 1.11.3

Using the following configuration, verification is invalid and cross-domain problems still exist

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

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links

You may also be interested in:
  • Use jQuery and JSONP to easily solve the problem of cross-domain access
  • Use jsonp to perfectly solve cross-domain problems
  • jQuery $.getJSON() cross-domain request
  • 3 common methods of js cross-domain request data
  • 8 solutions for js front-end to solve cross-domain problems (latest and most complete)
  • Nginx configuration cross-domain request Access-Control-Allow-Origin * detailed explanation
  • How to use nginx to solve cross-domain access of cookies
  • Explanation of the configuration method for processing AJAX cross-domain requests in Nginx server
  • Detailed explanation of Java cross-domain problem handling
  • Two ways to solve cross-domain requests in java
  • How to solve cross-domain problems when debugging with vue+Java backend
  • How to use CORS to implement JavaWeb cross-domain request issues
  • Detailed example of solution to java request cross-domain problem
  • Detailed explanation of JS cross-domain (Access-Control-Allow-Origin) front-end and back-end solutions

<<:  Using front-end HTML+CSS+JS to develop a simple TODOLIST function (notepad)

>>:  MySQL 5.7.18 zip version installation and configuration method graphic tutorial (win7)

Recommend

MySQL 8.0.12 Installation and Configuration Tutorial

This article records the detailed tutorial for in...

How to use docker to deploy front-end applications

Docker is becoming more and more popular. It can ...

Detailed explanation of MySQL custom functions and stored procedures

Preface This article mainly introduces the releva...

About Generics of C++ TpeScript Series

Table of contents 1. Template 2. Generics 3. Gene...

MySQL column to row conversion, method of merging fields (must read)

Data Sheet: Column to row: using max(case when th...

Use of MySQL DDL statements

Preface The language classification of SQL mainly...

Rsync+crontab regular synchronization backup under centos7

Recently, I want to regularly back up important i...

Mysql master-slave synchronization configuration scheme under Centos7 system

Preface Recently, when working on a high-availabi...

How to add vim implementation code examples in power shell

1. Go to Vim's official website to download t...

HTML tutorial, easy to learn HTML language

1. <body background=image file name bgcolor=co...

Nginx operation and maintenance domain name verification method example

When configuring the interface domain name, each ...

MySQL primary key naming strategy related

Recently, when I was sorting out the details of d...

MySQL 5.7.17 installation and configuration method graphic tutorial

This article shares the installation and configur...