In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the "nginx cross-domain configuration tutorial". In the daily operation, I believe many people have doubts about the nginx cross-domain configuration tutorial. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts of "nginx Cross-Domain configuration tutorial". Next, please follow the editor to study!
Configure nginx cross-domain
As a front-end, you can't avoid the cross-domain problem. One of the solutions is to use nginx proxy. This article only discusses the solution of using nginx.
The configuration is as follows, only the server part is shown, and the http part is configured according to the default configuration:
# # https serverserver {listen 19443 ssl; server_name localhost 127.0.0.1; ssl_certificate local.crt; ssl_certificate_key local.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers HIGH Vista Null ssl; server_name localhost Md 5; ssl_prefer_server_ciphers on Access_log logs/host.access.log main; location / {root html; index index.html index.htm;} location / scanIdCard/ {proxy_pass https://127.0.0.1:9199; If ($request_method = 'OPTIONS') {add_header' Access-Control-Allow-Origin''*'; add_header 'Access-Control-Allow-Methods'' *'; add_header 'Access-Control-Max-Age' 1728000; add_header' Content-Type' 'text/plain; charset=utf-8' Add_header 'Content-Length' 0; add_header Access-Control-Allow-Headers' Authorization,X-Requested-With,Content-Type,Origin,Accept' always; return 200;} proxy_redirect off; proxy_set_header Host $host Proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; rewrite "^ / scanIdCard/ (. *) $" / $1 break;}}
Scenario description: this is the forwarding of a proxy ID scan. When the current project is deployed to the CVM, the user uses a browser to access the CVM. At this time, if you need to read ID information on the local computer, there will be a cross-domain problem. Why? Because the access address of the front-end project on the CVM must be the domain name + port number, such as www.baidu.com:19999, etc., while the service of the ID card reader is local, and the access address is localhost+, which is a different port from 19999, such as localhost:8999, etc., cross-domain problems arise. However, cross-domain is a limitation of the browser, not the server, which can be solved by setting CORS on the server.
In the configuration item, the https service listens to port 19443, so in the front-end page request, the request address must also be: https://127.0.0.1:19443/scanIdCard/********, so that the request can be forwarded to the nginx.
At this point, the study on the "nginx Cross-Domain configuration tutorial" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.