vue.js - After vue is packaged, the cross-domain problem of nginx server API request cannot be solved.
世界只因有你
世界只因有你 2017-06-26 10:49:58
0
1
1721

I packaged vue and sent it to the server, then placed it in the directory specified by the www subdomain name. When I make a request, I need to request the directory bound to the api subdomain name. This request caused a cross-domain prompt

Then I also configured it in nginx but there was no solution.

That is, I request www.daimatu.cn/api/login/index ajax post request and forward it to api.daimatu.cn/api/login/index

I have made a lot of settings in location / {} and location /api {} before. They were all obtained from Baidu online, but they didn’t work~!

Then I changed the requested address to online in my local computer, and there was no problem with local requests! It is passable and can operate normally. I compared the request hair on both sides and found that they are different! The Request Method of the local request to the online server is a normal GET POST. However, when I go from www to request the api online, the Request Method becomes OPTIONS instead of the normal GET POST and other request headers. I also searched and found how to set the OPTIONS request. At this time, cross-domain still cannot be solved!

As shown in the picture, it has become options

I would like to ask everyone how you configure it. My back-end language is PHP. Don't ask me to set up and change PHP. My local requests for local services and online services are all normal. There is only a problem with the online www forwarding request api. So no need to change the program.

Api request address: http://api.daimatu.cn/api/log...
Api account: admin
Api password: 123456
Api verification code: 1234
Please everyone The NGINX server asks me to use this API to check your configuration. I have been struggling for a long time without success! !

世界只因有你
世界只因有你

reply all(1)
阿神

Make the following configuration in location

add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';

Then restart the nginx service

service nginx reload
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!