How to add configuration to the server-side nginx.conf and solve the front-end cross-domain problem
How to add configuration in the server-side nginx.conf and solve the front-end cross-domain problem, I believe that many inexperienced people do not know what to do. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
Step one:
Http {. Add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Headers XmurRequestedMuth; 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,Content-Range,Range';.
Prompt
If the above cannot be solved, you need to change the voucher to true.
Add_header 'Access-Control-Allow-Credentials'' true'
So the whole thing is:
Add_header 'Access-Control-Allow-Origin'' * 'always; add_header' Access-Control-Allow-Credentials' 'true'; add_header' Access-Control-Allow-Headers' "Origin, X-Requested-With, Content-Type, Accept"; add_header 'Access-Control-Allow-Headers'' X add_header 'Access-Control-Allow-Methods'' GET,POST,PUT,DELETE,OPTIONS' Add_header 'Access-Control-Allow-Headers'' DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range'; some Taoists use phpstudy configuration, so it won't work with the above results
So I tested a new way:
Server {listen 80; server_name www.crm.com crm.com; root "F:/wwwroot/taobao.com/pc2"; add_header Access-Control-Allow-Origin * always; add_header Access-Control-Allow-Methods * always; add_header Access-Control-Allow-Headers * always Location / {add_header Access-Control-Allow-Origin * always; add_header Access-Control-Allow-Methods * always; add_header Access-Control-Allow-Headers * always; index index.php index.html error/index.html; error_page 400 / error/400.html Error_page 403 / error/403.html; error_page 404 / error/404.html; error_page 500 / error/500.html; error_page 501 / error/501.html; error_page 502 / error/502.html; error_page 503 / error/503.html; error_page 504 / error/504.html Error_page 505 / error/505.html; error_page 506 / error/506.html; error_page 507 / error/507.html; error_page 509 / error/509.html; error_page 510 / MFCRM / error/509.html; error_page 510 / MFCRM / APIqqqingx.ht access; autoindex off } location ~\ .php (. *) ${add_header Access-Control-Allow-Origin * always; add_header Access-Control-Allow-Methods * always; add_header Access-Control-Allow-Headers * always; fastcgi_pass 127.0.0.1 always; add_header Access-Control-Allow-Headers 9000; fastcgi_index index.php Fastcgi_split_path_info ^ ((? U). +\ .php) (/?. +) $; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; include fastcgi_params;}}
I don't know if it's the environment or something else, but sometimes it doesn't work.
After reading the above, have you learned how to add configuration to the server-side nginx.conf and how to solve the front-end cross-domain problems? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!