nginx重定向到Docker容器服务

eh57zj3b  于 2023-03-12  发布在  Nginx
关注(0)|答案(1)|浏览(190)

我正在尝试将请求重定向到Docker容器服务上不同端口中的服务。
docker-compose.yml

nginx:
        image: nginx:1.23.3
        volumes:
          - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
          - ./nginx/src:/etc/nginx/html
        depends_on:
          - pinpoint-web
        restart: always
        ports:
          - 81:80
        networks:
          support-network:

    pinpoint-web:
        image: "pinpointdocker/pinpoint-web:${PINPOINT_VERSION}"
        restart: always
        expose:
          - "9997"
        ports:
          - "9997:9997"
          - "8080:8080"
        networks:
          support-network:

我的Nginx配置:

upstream pinpoint-web {
        server pinpoint-web:8080;
    }

    server {
        listen 80;

        location /pinpoint-web {
            rewrite /pinpoint-web/(.*) http://pinpoint-web:8080/$1 break;
            proxy_pass http://pinpoint-web;
        }
    }

但是当我尝试“http://localhost:81/pinpoint-web”时,我收到了如下错误:

{
     "timestamp": 1678301663635,
     "status": 404,
     "error": "Not Found",
     "message": "No message available",
     "path": "/pinpoint-web",
     "data": null
    }

Nginx日志:

2023-03-08 13:54:19 2023/03/08 18:54:19 [notice] 1#1: start worker process 29
2023-03-08 13:54:19 2023/03/08 18:54:19 [notice] 1#1: start worker process 30
2023-03-08 13:54:19 2023/03/08 18:54:19 [notice] 1#1: start worker process 31
2023-03-08 13:54:19 2023/03/08 18:54:19 [notice] 1#1: start worker process 32
2023-03-08 13:54:23 172.22.0.1 - - [08/Mar/2023:18:54:23 +0000] "GET /pinpoint-web HTTP/1.1" 404 139 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.63" "-"
cotxawn7

cotxawn71#

请求似乎已发送到pinpoint-web服务,但您的重写规则看起来不正确。请将位置更改为以下位置,然后重试:

location ~ /pinpoint-web/(.*) {
   proxy_pass http://pinpoint-web/$1;
}

相关问题