How to write the server of nginx?

my vue port is 8090 background port is 8080
it is first configured in the proxyTable of vue

"/ api": {

            target: "http://localhost:8080",
            changeOrigin: true,
            pathRewrite: { 
                "^/api": "http://localhost:8080" // 
            } 
    },
   

API such as / api/system/troubles/login
Local can cross-domain normally
now I want to implement it with nginx

server {

    listen 1111;
    server_name localhost;

    location ^~/api/ {
    rewrite ^/api/(.*) /$1 break;
    proxy_pass http://localhost:8080/;
    }
}

listen write 8090 will report port occupation, casually write 1111 can not cross-domain report 404, or location error? How should I write

Mar.05,2022

can we all use nginx agents?

server {

    listen 8088;
    server_name localhost;
    location / {
        proxy_pass http://localhost:8090
    }
    
    location /api/ {
        proxy_pass http://localhost:8080/;
    }
}

do you want to delegate locally to the test environment?

upstream local_server{
    -sharp  http://localhost:8080/:
    server 127.0.0.1:8080 max_fails=3     fail_timeout=30s;
}

upstream vue_server{
    -sharp  :
    server 202.xxx.xx.xx:80   max_fails=3     fail_timeout=30s;
}


server{
    -sharp 
    listen 8090;
    
    location / {  
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header REMOTE-HOST $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  
        proxy_pass http://local_server;

    }
   location ~*.(json|jsp|do|action)$   {
    proxy_pass http://vue_server;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header REMOTE-HOST $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}
  • How to write the server of nginx?

    my vue port is 8090 background port is 8080 it is first configured in the proxyTable of vue api : { target: http: localhost:8080 , changeOrigin: true, pathRewrite: { ^ api : http: loc...

    Mar.05,2022
  • How to write the server of nginx?

    my vue port is 8090 background port is 8080 it is first configured in the proxyTable of vue api : { target: http: localhost:8080 , changeOrigin: true, pathRewrite: { ^ api : http: loc...

    Mar.05,2022
Menu