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

InnoDB type MySql restore table structure and data

Prerequisite: Save the .frm and .ibd files that n...

Getting Started Guide to Converting Vue to React

Table of contents design Component Communication ...

Implementation of CSS loading effect Pac-Man

emmm the name is just a random guess 2333 Preface...

Detailed explanation of WeChat Mini Program official face verification

The mini program collected user personal informat...

Vue's vue.$set() method source code case detailed explanation

In the process of using Vue to develop projects, ...

Detailed explanation of how to dynamically set the browser title in Vue

Table of contents nonsense text The first router/...

VMware Workstation Installation (Linux Kernel) Kylin Graphic Tutorial

This article shares with you how to install Kylin...

MySQL encoding utf8 and utf8mb4 utf8mb4_unicode_ci and utf8mb4_general_ci

Reference: MySQL character set summary utf8mb4 ha...

How to use CSS3 to implement a queue animation similar to online live broadcast

A friend in the group asked a question before, th...

Use a diagram to explain what Web2.0 is

Nowadays we often talk about Web2.0, so what is W...

HTML form value transfer example through get method

The google.html interface is as shown in the figur...

How to configure redis sentinel mode in Docker (on multiple servers)

Table of contents Preface condition Install Docke...

JavaScript manual implementation of instanceof method

1. Usage of instanceof instanceof operator is use...