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

How to solve nginx 503 Service Temporarily Unavailable

Recently, after refreshing the website, 503 Servi...

HTML realizes real-time monitoring function of Hikvision camera

Recently the company has arranged to do some CCFA...

JavaScript implements asynchronous acquisition of form data

This article example shares the specific code for...

Detailed explanation of commonly used nginx rewrite rules

This article provides some commonly used rewrite ...

Complete steps to implement face recognition login in Ubuntu

1. Install Howdy: howdy project address sudo add-...

Problems encountered in using MySQL

Here are some problems encountered in the use of ...

IE6 BUG and fix is ​​a preventive strategy

Original article: Ultimate IE6 Cheatsheet: How To...

How to use Nginx proxy to surf the Internet

I usually use nginx as a reverse proxy for tomcat...

React nested component construction order

Table of contents In the React official website, ...

The difference between datatime and timestamp in MySQL

There are three date types in MySQL: date(year-mo...

Do you know how to use mock in vue project?

Table of contents first step: The second step is ...

How to configure Nginx to support ipv6 under Linux system

1. Check whether the existing nginx supports ipv6...