Solution to the conflict between nginx and backend port

Solution to the conflict between nginx and backend port

question:

When developing the Alice management system, I found that all backend interfaces generated 404 errors when requested for the first time, but succeeded the second time.

Positioning Problem

I checked the nginx error log and found the following error. I mistakenly thought that the error occurred because the html folder had insufficient permissions, which caused the file to be unable to be written. So after opening the permissions, I found that it still didn't work. I searched on Google but still couldn't find a solution. I put it aside for the time being. When I was looking for the error again the next day, I accidentally opened port 8081. When you visited localhost:8081 and 127.0.0.1:8081 , the contents were different.

At that time, I wondered if there was a port conflict, so I opened the file and found the nginx config file and our project configuration file. I found that there was a port conflict. When you access the backend, you will find that the request will be sent to nginx static files, so a 404 error will be generated.

server {
  listen 8081;
  server_name 127.0.0.1;

  #charset koi8-r;

  #access_log logs/host.access.log main;

  location / {
    root html;
    index index.html index.htm;
  }
server {
  # Platform port listen 8100;
  server_name localhost;

  location / {
    proxy_pass http://localhost:4200/;
  }

  location /api/ {
    proxy_pass http://localhost:8081/;
  }
  #error_page 404 /404.html;

  # redirect server error pages to the static page /50x.html
  #
  error_page 500 502 503 504 /50x.html;
  location = /50x.html {
    root /usr/share/nginx/html;
  }
}

Workaround

Change the backend port and the nginx configuration of the project.

Remaining issues:

When the background is started, the content of accessing localhost:8081 is different from that of 127.0.0.1:8081 The same content is available when the background is closed.

The reasons may be as follows:
localhost: The system uses the permissions of the current user on this machine to access
127.0.0.1: This means that the local machine is accessed through the network

When nginx conflicts with the backend, why does it access nginx internal files in odd numbers and access the backend in even numbers (why can it occupy the same interface)?

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:
  • Nginx reverse proxy and load balancing practice
  • In-depth understanding of the matching logic of Server and Location in Nginx
  • Nginx access control and parameter tuning methods
  • Detailed explanation of the best practice of Django+uwsgi+Nginx online
  • How to increase your web performance by 3 times by turning on a parameter in Nginx
  • How to use PHP to count the User Agent data of Nginx logs
  • How to add Nginx to system services in CentOS7
  • How to deploy multiple Vue projects under the same domain name using nginx and use reverse proxy
  • Python implementation example of monitoring differences in Nginx configuration files and sending email alerts
  • How to block and prohibit web crawlers in Nginx server

<<:  A brief analysis of mysql index

>>:  Detailed explanation of virtual DOM and diff algorithm in react

Recommend

HTML 5.1 learning: 14 new features and application examples

Preface As we all know, HTML5 belongs to the Worl...

MySQL 5.7.17 winx64 installation and configuration tutorial

Today I installed the MySQL database on my comput...

Detailed explanation of root directory settings in nginx.conf

There are always some problems when configuring n...

Vue.js $refs usage case explanation

Despite props and events, sometimes you still nee...

Introduction to Common XHTML Tags

<br />For some time, I found that many peopl...

Installation tutorial of mysql5.7.21 decompression version under win10

Install the unzipped version of Mysql under win10...

Sample code for achieving small triangle border effect with pure CSS3+DIV

The specific code is as follows: The html code is...

Initial settings after installing Ubuntu 16 in the development environment

The office needs Ubuntu system as the Linux devel...

How to reset MySQL root password under Windows

Today I found that WordPress could not connect to...

Vue uses rules to implement form field validation

There are many ways to write and validate form fi...

Architecture and component description of docker private library Harbor

This article will explain the composition of the ...

Open the Windows server port (take port 8080 as an example)

What is a Port? The ports we usually refer to are...