前提
リバースプロキシ(nginx)を構築してサブドメインへのアクセスの際に別に動いているnginxでページを表示させたいです。
下記の図のlocalhost:80(黒線)は正常に動いており、web-site0.localhost:80(赤線)が意図どおりに動いておりません。
実現したいこと
- web-site0.localhost:80(赤線)へアクセスしたとき、web-site0/index.htmlを表示させたいです。
発生している問題・エラーメッセージ
web-site0.localhost:80(赤線)へアクセスすると
ブラウザでは502 Bad Gateway
docker compose up でのログでは下記が表示されます。
gateway | 172.26.0.1 - - [29/Dec/2022:06:56:43 +0000] "GET / HTTP/1.1" 502 559 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36" gateway | 2022/12/29 06:56:43 [error] 29#29: *7 connect() failed (111: Connection refused) while connecting to upstream, client: 172.26.0.1, server: web-site0.localhost, request: "GET / HTTP/1.1", upstream: "http://172.26.0.2:8080/", host: "web-site0.localhost" gateway | 172.26.0.1 - - [29/Dec/2022:06:56:43 +0000] "GET /favicon.ico HTTP/1.1" 502 559 "http://web-site0.localhost/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36" gateway | 2022/12/29 06:56:43 [error] 29#29: *7 connect() failed (111: Connection refused) while connecting to upstream, client: 172.26.0.1, server: web-site0.localhost, request: "GET /favicon.ico HTTP/1.1", upstream: "http://172.26.0.2:8080/favicon.ico", host: "web-site0.localhost", referrer: "http://web-site0.localhost/"
該当のソースコード
yml
1version: '3.9' 2services: 3 web-site0: 4 image: nginx:latest 5 container_name: web-site0 6 volumes: 7 - ./web-site0:/etc/nginx/html 8 ports: 9 - 8080:80 10 restart: always 11 12 gateway: 13 image: nginx:latest 14 container_name: gateway 15 ports: 16 - 80:80 17 volumes: 18 - ./nginx/nginx.conf:/etc/nginx/nginx.conf 19 - ./html:/etc/nginx/html 20 depends_on: 21 - web-site0 22 restart: always
conf
1events { 2 worker_connections 1024; 3} 4 5http { 6 server { 7 listen 80; 8 server_name localhost; 9 location / { 10 } 11 } 12 13 server { 14 listen 80; 15 server_name web-site0.localhost; 16 location / { 17 proxy_pass http://web-site0:8080/; 18 } 19 } 20}
※使用しているコード全体はこちらに上げております。
├── docker-compose.yml ├── html │ └── index.html # localhost:80(黒線)へアクセスがあった際に表示される ├── nginx │ └── nginx.conf └── web-site0 └── index.html # web-site0.localhost:80(赤線)へアクセスがあった際に表示されたい(現在出来ていない)
再現方法
shell
1% git clone https://github.com/Uyutaka/docker-nginx-reverse-proxy.git 2% cd docker-nginx-reverse-proxy 3% docker compose up
試したこと
「connect() failed (111: Connection refused) while connecting to upstream」等で検索して解決方法を探しました。
補足情報(FW/ツールのバージョンなど)
shell
1% docker compose version 2Docker Compose version v2.13.0 3% docker version 4Client: 5 Cloud integration: v1.0.29 6 Version: 20.10.21 7 API version: 1.41 8 Go version: go1.18.7 9 Git commit: baeda1f 10 Built: Tue Oct 25 18:01:18 2022 11 OS/Arch: darwin/arm64 12 Context: default 13 Experimental: true 14 15Server: Docker Desktop 4.15.0 (93002) 16 Engine: 17 Version: 20.10.21 18 API version: 1.41 (minimum version 1.12) 19 Go version: go1.18.7 20 Git commit: 3056208 21 Built: Tue Oct 25 17:59:41 2022 22 OS/Arch: linux/arm64 23 Experimental: false 24 containerd: 25 Version: 1.6.10 26 GitCommit: 770bd0108c32f3fb5c73ae1264f7e503fe7b2661 27 runc: 28 Version: 1.1.4 29 GitCommit: v1.1.4-0-g5fd4c4d 30 docker-init: 31 Version: 0.19.0 32 GitCommit: de40ad0
参考にさせていただいたレポジトリ
参考にさせていただいたレポジトリ
回答1件