How to use Nginx to deal with cross-domain issues in the Vue development environment

WBOY
Release: 2023-05-18 08:28:05
forward
1612 people have browsed it

1. Requirements

The local test domain name is the same as the online domain name in order to correctly deliver cookies and perform SSO testing.

Note: Since the relevant cookies are added to the fourth-level domain name after sso login, the local test domain name and the online interface domain name need to be the same.

2. Solution

Configure the host file so that the online domain name points to localhost:

127.0.0.1 product.xxx. xxx.com

Configure nginx for corresponding forwarding:

server {
  listen    80;
  listen    [::]:80;
  server_name ${product.xxx.xxx.com};

  location /api {
    proxy_pass https://${ip.ip.ip.ip};
    proxy_set_header host $host;
  }

  location / {
    proxy_pass http://localhost:8080;
    proxy_set_header host $host;
  }  
}
Copy after login

Configure vue.config.js to avoid invalid host header errors:

{
  devserver: {
    disablehostcheck: true
  }
}
Copy after login

The above is the detailed content of How to use Nginx to deal with cross-domain issues in the Vue development environment. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
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!