Nginx configures front-end and back-end projects

There are two sets of front-end projects, namely the foreground and the background

Only one set of spring boot is used on the back end

Deploy nginx after packaging

1. listen is the listening port

2. server_name is the address of the server

3. location refers to the relative path

4. root is the address stored on the front page

5. index.html is the home page of the front-end project

6. proxy_pass is the forwarding address

Since the two sets of front-end projects correspond to a set of back-end projects, it is necessary to change the listening port when configuring another set of front-end projects. Here I use 80 for one and 8090 for the other. Since the back-end project is 8080, use For port 8090, it needs to be forwarded. Otherwise, 405 or other errors will appear in the front-end project. The forwarding is proxy_pass, and the front-end request depends on the IP forwarding to 8080. Otherwise, the 8090 interface cannot be adjusted.

server {
        listen       80;
        server_name  127.0.0.1;
        location / {
          root C:/news/news/dist;
          if (!-e $request_filename) {
            rewrite ^/(.*) /index.html last;
            break;
            }
        }
    }
    server {
        listen       8090;
            server_name  127.0.0.1;
            location / {
              root C:/news/news/admin-dist/dist;
              if (!-e $request_filename) {
                rewrite ^/(.*) /index.html last;
                break;
                }
            }
            location /prod-api/ {
            proxy_pass http://localhost:8080/;
            }
    }

Guess you like

Origin blog.csdn.net/m0_57666466/article/details/126662732