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

JS implements multiple tab switching carousel

Carousel animation can improve the appearance and...

Detailed explanation of the relationship between Vue and VueComponent

The following case reviews the knowledge points o...

How to set password for mysql version 5.6 on mac

MySQL can be set when it is installed, but it see...

Docker installation and configuration command code examples

Docker installation Install dependency packages s...

Vue Page Stack Manager Details

Table of contents 2. Tried methods 2.1 keep-alive...

How to configure domestic sources in CentOS8 yum/dnf

CentOS 8 changed the software package installatio...

Navicat for MySql Visual Import CSV File

This article shares the specific code of Navicat ...

Let IE6, IE7, IE8 support CSS3 rounded corners and shadow styles

I want to make a page using CSS3 rounded corners ...

win10 docker-toolsbox tutorial on building a php development environment

Download image docker pull mysql:5.7 docker pull ...

React gets input value and submits 2 methods examples

Method 1: Use the target event attribute of the E...

The front-end page pop-up mask prohibits page scrolling

A problem that front-end developers often encount...

Angular environment construction and simple experience summary

Introduction to Angular Angular is an open source...

A brief discussion on ifnull() function similar to nvl() function in MySQL

IFNULL(expr1,expr2) If expr1 is not NULL, IFNULL(...

A brief discussion on the efficiency of MySQL subquery union and in

Recent product testing found a problem that when ...

Solution to data duplication when using limit+order by in MySql paging

Table of contents summary Problem Description Ana...