In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
In this article, the editor introduces in detail "how to use Nginx reverse proxy to solve cross-domain problems". The content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to use Nginx reverse proxy to solve cross-domain problems" can help you solve your doubts.
problem
In previous articles on cross-domain resource sharing, it was mentioned that when you want to send a cookie,access-control-allow-origin, you cannot set it to *. You must specify a clear domain name that is consistent with the requested web page. This is the kind of problem encountered in collaboration with others in the development of this project.
Solution idea
Generally speaking, you can use cors cross-domain resource sharing with the backend to set access-control-allow-origin to the accessed domain name, which requires the cooperation of the backend, and some browsers do not support it.
Based on the cooperation with the background of the partner, the nginx directional proxy is used to satisfy the browser's homology strategy to realize cross-domain.
Realization method
Reverse proxy concept
Reverse proxy (reverse proxy) means that the proxy server accepts the connection request on the internet, then forwards the request to the server on the internal network, and returns the result obtained from the server to the client requesting the connection on the internet. At this time, the proxy server behaves as a server externally. The reverse proxy server is like the original server to the client, and the client does not need to make any special settings. The client sends a normal request to the content in the reverse proxy's namespace (name-space), which then determines where to forward the request (the original server) and returns the obtained content to the client as if it were already its own.
The steps of using nginx reverse proxy to realize Cross-domain
Download the package and build the nginx environment.
Modify the nginx configuration file, find the ngixn.conf file, and modify the relevant configuration
Http {include mime.types; default_type application/octet-stream; sendfile on; server {listen 8000; # listens on port 8000, which can be changed to another port server_name localhost; # the domain name of the current service location / wili/api/ {proxy_pass http://chick.platform.deva.wili.us/api/; # add proxy configuration proxy_http_version 1.1 with access path recorded as / will/api } location / {proxy_pass http://localhost:8001; proxy_http_version 1.1;} error_page 500502 503 504 / 50x.html; location = / 50x.html {root html;}
Explanation of configuration:
As can be seen from the configuration information, we asked nginx to listen on port 8000 of localhost, and both website an and website b are accessed through port 8000 of localhost.
We have specially configured a "/ will/api" access so that all addresses starting with "will/api" are transferred to "" for processing.
Access address modification
Now that we have configured nginx, all visits have to go through nginx, not the original address of the website (a website localhost:8001,b website). So change the request interface in a website to. Next, start nginx and access 8000 of the configuration.
It is important to note that nginx startup may conflict with the port and cause the startup to be unsuccessful. Check the Task Manager to see if the startup is successful.
After reading this, the article "how to use Nginx reverse proxy to solve cross-domain problems" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it yourself. If you want to know more about related articles, you are welcome to follow the industry information channel.
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
© 2024 shulou.com SLNews company. All rights reserved.