Задать вопрос
@romaro

Почему Nginx не проксирует в Докере?

Мой compose:
volumes:
  nginx-vol:
    name: gp-nginx-vol
    external: true

services:
  site:
    image: node:16-alpine3.15
    container_name: gp-site-dev
    expose: [3000]
    ports:
      - 3000:3000
    volumes:
      - type: bind
        source: /home/romaro/gp
        target: /home/romaro/gp
    working_dir: /home/romaro/gp
    command: yarn s
  nginx:
    build: ./docker/nginx
    container_name: gp-nginx
    expose: [80, 443]
    ports:
      - 80:80
      - 443:443
    volumes:
      - type: volume
        source: nginx-vol
        target: /var/log/nginx
      - type: bind
        source: /home/romaro/gp/files
        target: /etc/static
    depends_on:
      - site


Конфиг Nginx:
user nginx;
worker_processes 1;
pcre_jit on;

error_log	/var/log/nginx/error.log crit;
pid		/var/log/nginx/nginx.pid;

events {
    worker_connections		1024;
    multi_accept			on;
}

http {
    include 		mime.types;
    default_type	application/octet-stream;

    sendfile			on;
    sendfile_max_chunk	128k;
    tcp_nopush			on;

    tcp_nodelay		on;
    keepalive_timeout	30s;
    keepalive_requests	100;
	
    reset_timedout_connection	on;
    client_body_timeout			10;
    client_header_timeout		10;

    server_tokens off;

    types_hash_max_size 4096;

    server {
        listen       		80;
        listen       		[::]:80;
        server_name  		localhost;

		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_set_header Host $http_host;
		proxy_set_header X-Forwarded-Proto $scheme;

		# NodeJS
		location / {
			proxy_pass_header Server;
			proxy_pass http://site:3000;
            
			gzip			on;
			gzip_min_length		2048;
			gzip_comp_level		3;
			gzip_proxied		any;
			gzip_types		text/plain text/css text/javascript;
		}

        # Static
        location /static/ {
            root /etc;
            autoindex off;
        }

        error_page 404 /404.html;
        location = /404.html {
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
    }
}


Dockerfile:
FROM nginx:1.22.0-alpine

COPY nginx.conf /etc/nginx/nginx.conf


Контейнерный сервер успешно стартует на 3000 порту и по идее должны быть доступен по ссылке localhost, но я получаю ошибку 404. При этом статика (localhost/static/test.txt) отдается исправно:
[romaro@ora19c gp]$ docker-compose up
[+] Running 2/0
 ⠿ Container gp-site-dev  Created                                                                                                                                       0.0s
 ⠿ Container gp-nginx     Created                                                                                                                                       0.0s
Attaching to gp-nginx, gp-site-dev
gp-site-dev  | yarn run v1.22.19
gp-site-dev  | $ npx ts-node --project packages/customer/tsconfig.json packages/customer/main.ts
gp-nginx     | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
gp-nginx     | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
gp-nginx     | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
gp-nginx     | 10-listen-on-ipv6-by-default.sh: info: IPv6 listen already enabled
gp-nginx     | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
gp-nginx     | /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
gp-nginx     | /docker-entrypoint.sh: Configuration complete; ready for start up
gp-site-dev  | {"level":30,"time":1657270591970,"pid":39,"hostname":"23ef9616da41","msg":"Server listening at http://127.0.0.1:3000"}
gp-nginx     | 10.0.2.2 - - [08/Jul/2022:08:57:18 +0000] "GET / HTTP/1.1" 404 146 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0"
gp-nginx     | 10.0.2.2 - - [08/Jul/2022:08:57:18 +0000] "GET /favicon.ico HTTP/1.1" 404 146 "http://localhost/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0"
gp-nginx     | 10.0.2.2 - - [08/Jul/2022:08:59:00 +0000] "GET /static/test.txt HTTP/1.1" 200 5 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0"
  • Вопрос задан
  • 310 просмотров
Подписаться 1 Средний 3 комментария
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы