[Vuejs]-Use nginx proxy resolves cross-domain issues but it still exist cross-domain?

0👍

I wonder that this works without specifying the route (URI) you want to have a proxy for … you should do it like:

server {
  listen 8081;
  location /api {
    proxy_pass http://127.0.0.1:8083/api;
  }
}

OR adding the necessary headers in nginx – this would then allow you to use one port for front end (8081) serving and another for the backend API (8083) without having problems with CORS:

server {
  listen 8083;
  location / {
    add_header 'Access-Control-Allow-Origin' '*';
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Methods' 'OPTIONS,GET,HEAD,POST,MERGE,PATCH,DELETE,PUT';
  }
}

Code/Configuration not tested… but I hope that makes sense for you

Leave a comment