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

Implementation of remote Linux development using vscode

Say goodbye to the past Before vscode had remote ...

Vue implements scrollable pop-up window effect

This article shares the specific code of Vue to a...

React non-parent-child component parameter passing example code

React is a JAVASCRIPT library for building user i...

MySQL startup error InnoDB: Unable to lock/ibdata1 error

An error message appears when MySQL is started in...

Douban website's method for making small changes to website content

<br />Reading is a very important part of th...

Mysql Sql statement comments

You can add comments to MySQL SQL statements. Her...

HTML form and the use of form internal tags

Copy code The code is as follows: <html> &l...

HTML table tag tutorial (3): width and height attributes WIDTH, HEIGHT

By default, the width and height of the table are...

MySQL table type storage engine selection

Table of contents 1. View the storage engine of t...

How to use Vue cache function

Table of contents Cache function in vue2 Transfor...

Bootstrap 3.0 study notes CSS related supplement

The main contents of this article are as follows:...

Solution to forgetting MySQL root password in MACOS

MySQL is a relational database management system ...

Linux uses join -a1 to merge two files

To merge the following two files, merge them toge...