Home Operation and Maintenance Nginx Analysis of the principle of nginx solving cross-domain problems

Analysis of the principle of nginx solving cross-domain problems

Jun 13, 2020 pm 04:30 PM
nginx principle Cross domain

Analysis of the principle of nginx solving cross-domain problems

Let’s first talk about what cross-domain is:

The same-origin policy restricts how documents or scripts loaded from the same source can interact with Interact with a resource from another source. This is an important security mechanism for isolating potentially malicious files. Read operations between different sources are generally not allowed.

Then let’s talk about what is the same origin:

If the protocol, port (if specified) and domain name of the two pages are the same, then the two pages have the same origin. Same source.

Analysis of the principle of nginx solving cross-domain issues:

For example:

The domain name of the front-end server is: fe.server.com

The domain name of the back-end service is: dev.server.com

Now when I make a request to dev.server.com from fe.server.com, it will definitely appear cross-domain.

Now we only need to start an nginx server, set server_name to fe.server.com, and then set the corresponding location to intercept front-end cross-domain requests, and finally proxy the request back to dev.server.com. As shown in the following configuration:

server {
        listen       80;
        server_name  fe.server.com;
        location / {
                proxy_pass dev.server.com;
        }
}
Copy after login

This can perfectly bypass the browser's same-origin policy.

fe.server.com's access to nginx's fe.server.com is a same-origin access, and the request forwarded by nginx to the server will not trigger the browser's same-origin policy.

Recommended tutorial: nginx tutorial

The above is the detailed content of Analysis of the principle of nginx solving cross-domain problems. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to allow external network access to tomcat server How to allow external network access to tomcat server Apr 21, 2024 am 07:22 AM

How to allow external network access to tomcat server

What are the nginx start and stop commands? What are the nginx start and stop commands? Apr 02, 2024 pm 08:45 PM

What are the nginx start and stop commands?

How to run thinkphp How to run thinkphp Apr 09, 2024 pm 05:39 PM

How to run thinkphp

Welcome to nginx!How to solve it? Welcome to nginx!How to solve it? Apr 17, 2024 am 05:12 AM

Welcome to nginx!How to solve it?

How to register phpmyadmin How to register phpmyadmin Apr 07, 2024 pm 02:45 PM

How to register phpmyadmin

How to deploy nodejs project to server How to deploy nodejs project to server Apr 21, 2024 am 04:40 AM

How to deploy nodejs project to server

How to solve the problem of nginx when accessing the website How to solve the problem of nginx when accessing the website Apr 02, 2024 pm 08:39 PM

How to solve the problem of nginx when accessing the website

How to communicate between docker containers How to communicate between docker containers Apr 07, 2024 pm 06:24 PM

How to communicate between docker containers

See all articles