简体   繁体   English

Nginx 无法从 docker-compose 找到上游

[英]Nginx can't find upstream from docker-compose

I am trying to run a nginx proxy server with a ktor java server behind.我正在尝试运行带有 ktor java 服务器的 nginx 代理服务器。 However, nginx throws "111: Connection refused" with those configurations.但是,nginx 会在这些配置中抛出“111:连接被拒绝”。 I've tried the "setting upstream server name from localhost to docker compose name" on web but it didn't help anything.我已经在网络上尝试过“将上游服务器名称从 localhost 设置为 docker compose name”,但它没有任何帮助。
Thank you in advance, and sorry for my poor english.预先感谢您,并为我糟糕的英语感到抱歉。
docker-compose.yml docker-compose.yml

version: "3.8"
services:
  nginx:
    image: nginx:1.19.3
    ports:
      - 80:80
      - 443:443
    volumes:
      - ./Nginx/logs:/var/log/nginx
      - ./Nginx/confs:/etc/nginx/conf.d
      - ./Nginx/confs:/etc/nginx/keys
  mariadb:
    image: mariadb:10.5.6
    ports:
      - 3306:3306
    volumes:
      - ./Mariadb/data:/var/lib/mysql
      - ./Mariadb/confs:/etc/mysql/conf.d
      - ./Mariadb/inits:/docker-entrypoint-initdb.d
    env_file:
      - .env
    environment:
      TZ: Asia/Seoul
      MYSQL_USER: dockhyub
  yangjin208:
    build: ./Yangjin208
    ports:
      - "3000:8080"
    env_file:
      - .env
      - ./Yangjin208/.env
    links:
      - mariadb:sql

yangjin208.conf under ./Nginx/confs ./Nginx/confs 下的 yangjin208.conf

upstream yangjin208_app {
    server yangjin208:3000;
}

server {
    listen 80;
    server_name localhost;

    location / {
        proxy_pass http://yangjin208_app;
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Host $server_name;
    }
}

localhost:3000 is accessible by browser, and has no problems. localhost:3000 可以通过浏览器访问,没有问题。

I think you're not using the yangjin208.conf in nginx.我认为您没有在 nginx 中使用 yangjin208.conf。 Rename yangjin208.conf to default.conf.将 yangjin208.conf 重命名为 default.conf。

So, I've found the problem - It seems like the docker internal network uses the original port instead of the port changed from docker-compose.yml's "ports" configuration.所以,我发现了问题 - 似乎 docker 内部网络使用原始端口而不是从 docker-compose.yml 的“端口”配置更改的端口。 I was using the port 3000 (Port declared from docker-compose) instead of 8080 (The original port), and that was the reason it didn't work.我使用的是端口 3000(从 docker-compose 声明的端口)而不是 8080(原始端口),这就是它不起作用的原因。 Thanks for everyone.谢谢大家。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM