如何从 NGINX proxy_pass 中删除前缀(重写似乎不起作用)?

如何从 NGINX proxy_pass 中删除前缀(重写似乎不起作用)?

我有以下内容...

version: '2'

services:
  main-nginx:
    image: nginx:latest
    container_name: nginx
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf
      - ./nginx/src:/usr/src
    ports:
      - "80:80"
      - "443:443"
  ui:
    container_name: ui
    image: cbusha-ui:latest
  be:
    container_name: be
    image: cbusha-be:latest
    ports:
      - "8080:8080"

server {
    listen 80;
    listen  443 ssl;
    ssl_certificate /usr/src/site.crt;
    ssl_certificate_key /usr/src/site.key;
    server_name me.com;
    # include /usr/src/allow-cloudflare-only.conf
    location /services {
        rewrite /services/(.*) /$1  break;
        proxy_pass  http://be:8080;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header HOST $host/work;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Frame-Options SAMEORIGIN;
    }
    location / {
        proxy_pass  http://ui:3000/;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Frame-Options SAMEORIGIN;
    }
}

当我尝试直接访问后端时,它运行正常......

在此处输入图片描述

但当我尝试使用 NGINX 代理时,我得到了 400

在此处输入图片描述

我错过了什么?

请注意,用户界面运行良好,所以...

在此处输入图片描述

另外要清楚的是,URL 中的名称,例如 http://be:8080 是 docker 中的容器名称,因此这些名称已被转发到 localhost 以证明它有效,但我也可以按原样直接在容器上运行它...

在此处输入图片描述

更新

所以我把它改成了

location /services {
  proxy_pass  http://be:8080/;
  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection "upgrade";
  proxy_set_header HOST $host;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

但我打电话的时候还是收到 400

https://localhost/services/heartbeat

当我打电话时,结果是 200

http://localhost:8080/心跳

相关内容