In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces how to solve the cross-domain failure of configuration in nginx. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.
The cross-domain configuration of nginx does not take effect as follows
Server {listen 80; server_name localhost; # API forwarding location / api/ {# allows request address cross-domain * as wildcard add_header 'Access-Control-Allow-Origin'' *'; # set request method cross-domain add_header 'Access-Control-Allow-Methods'' GET, POST, OPTIONS, PUT, DELETE' # set whether to allow cookie to transmit add_header 'Access-Control-Allow-Credentials'' true'; # set request headers why not set wildcards * because add_header 'Access-Control-Allow-Headers'' Authorization,Content-Type,Accept,Origin,User-Agent,DNT,Cache-Control,X-Mx-ReqToken,X-Data-Type,X-Requested-With,X-Data-Type,X-Auth-Token' is not supported # set reverse proxy proxy_pass 127.0.0.1virtual 8081max;}}
The cross-domain configuration of nginx on the Internet is mainly the above version, but many of them are copied and not really put into practice, so I wrote an article to remind those in need not to copy blindly and learn to analyze.
Nginx takes effect when the following configuration is modified.
Server {listen 80; server_name localhost; # API forwarding location / api/ {# allows request address cross-domain * as wildcard add_header 'Access-Control-Allow-Origin'' *'; # set request method cross-domain add_header 'Access-Control-Allow-Methods'' GET, POST, OPTIONS, PUT, DELETE' # set whether to allow cookie to transmit add_header 'Access-Control-Allow-Credentials'' true'; # set request headers why not set wildcards * because add_header 'Access-Control-Allow-Headers'' Authorization,Content-Type,Accept,Origin,User-Agent,DNT,Cache-Control,X-Mx-ReqToken,X-Data-Type,X-Requested-With,X-Data-Type,X-Auth-Token' is not supported # set options request processing if ($request_method = 'OPTIONS') {return 200;} # set reverse proxy proxy_pass 127.0.0.1 request_method 8081;}}
The main difference between the two codes is the following line of code
If ($request_method = 'OPTIONS') {return 200;}
Because the post request browser will send an options pre-check request, mainly send the request header to the server, and then send the real post request if the server allows it, so F12 sees that post will often send the request twice. Because the back-end java code does not handle the options request, when the options API request is reported, it will report 403 forbidden. Here, the nginx request to the options directly returns 2000.It does not need to reach the interface layer and directly allows the post response header to make the above failure configuration take effect.
A small knowledge point is given as a gift
Proxy_pass 127.0.0.1:8081/
Aiming at the question of whether or not to add this in the reverse proxy.
Visit http://localhost/api/user/login;
Add / then the actual access is 127.0.0.1:8081/user/login
If you do not add /, the actual access is 127.0.0.1:8081/api/user/login
This is the end of how to configure cross-domain failures in nginx. I hope the above content can be helpful to you and learn more. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
[root@DBBK1 changeIP] # cat view.sh #! / bin/shif [$#-ne 1]; then echo "USAGE:/bin/sh $0 ARG1"
© 2024 shulou.com SLNews company. All rights reserved.