'Nginx config in virtual host have CORS problem
I have problem in Nginx as I deployed my Vue application.
The API work normally in development mode, but have CORS problem after deploying, because our Backend-End use another service which was built on windows server.(But the Nginx was built in Linux with centos)
Therefore, I need to proxy on Nginx to handle CORS problem, I survey for two days and use whatever I know, but the CORS problem still exit, so I hope someone could help me.
The Entire API URL is
https://rccht.cna.com.tw/globalviewAPI/api/globalview/GetVideoList
I write API with env
${import.meta.env.VITE_CNA_API}/GetVideoList
The production env is
/gv-backend/globalviewAPI/api/globalview
``
The Nginx Config is
Because we use Vitual Host, the Nginx run two web applications, every web application have their own name, Nginx has second level folder under root.
I'm not sure if the Vitual Host cause subfolder affect the CORS or not, so I try to rewrite the URL for Nginx, but as you know, it still not work.
Please give me some advice and suggestion, thanks a lot.
Solution 1:[1]
Finally, I found the solution by myself.
The CORS problem is preflight request which caused by Axios.
The preflight request conditions could see this.
Because the Axios default Content-Type was application/json , and it triggered the preflight request. Therefore, I shouldn't to use Nginx proxy, the good solution was change the Content-Type of Axios.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | halfer |




