How to use Nginx to handle cross-domain Vue development environment

How to use Nginx to handle cross-domain Vue development environment

1. Demand

The local test domain name is the same as the online domain name to ensure correct cookie delivery and SSO testing.

Note: After SSO login, the relevant cookies are added to the fourth-level domain name, so the local test domain name and the online interface domain name must be the same.

2. Solution

Configure the Host file to point the online domain name 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;
  }  
}

Configure vue.config.js to avoid Invalid Host header error:

{
  devServer: {
    disableHostCheck: true
  }
}

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • vue-cli3 configuration and cross-domain processing method
  • How to handle cross-domain proxyTable in webpack+vue-cil
  • Vue-cli axios request method and cross-domain processing issues
  • In the Vue project, use axios cross-domain processing
  • Introduction to several common cross-domain processing methods in Vue
  • Summary of Vue's cross-domain problem handling and solutions

<<:  Common date comparison and calculation functions in MySQL

>>:  Docker practice: Python application containerization

Recommend

How to deploy MySQL and Redis services using Docker

Table of contents How to deploy MySQL service usi...

Regular expression usage in CSS selectors

Yes, CSS has regular expressions too (Amen) Two p...

Apache Log4j2 reports a nuclear-level vulnerability and a quick fix

Apache Log4j2 reported a nuclear-level vulnerabil...

Linux uses iptables to limit multiple IPs from accessing your server

Preface In the Linux kernel, netfilter is a subsy...

Do you know what are the ways to jump routes in Vue?

Table of contents The first method: router-link (...

Examples of new selectors in CSS3

Structural (position) pseudo-class selector (CSS3...

jQuery implements HTML element hiding and display

Let's imitate Taobao's function of displa...

Summary of various implementation methods of mysql database backup

This article describes various ways to implement ...

How to start the spring-boot project using the built-in linux system in win10

1. Install the built-in Linux subsystem of win10 ...

How to use mysqldump to backup MySQL data

1. Introduction to mysqldump mysqldump is a logic...

How to reset the root password in mysql8.0.12

After installing the database, if you accidentall...