NGINX + PHP через Traefik на Docker Compose

Конфигурация Traefik

Создать директории для приложения conf, www. В www создаем директорию html

В conf копируем настройки NGINX. Скачать настройки NGINX

Файл конфигурации conf/nginx.conf:

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 4096;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;
	
	include /etc/nginx/conf.d/*.conf;

    server {
        listen       80;
        listen       [::]:80;
        server_name  _;
        root         /usr/share/nginx/html;
		
		index	index.php;

		charset	utf-8;
		
		location ~* \.php$ {
			include fastcgi_params;
			fastcgi_split_path_info ^(.+\.php)(/.+)$;
			fastcgi_pass prefix-php:9000;
			fastcgi_index index.php;
			fastcgi_param SCRIPT_FILENAME $request_filename;
			fastcgi_param QUERY_STRING    $query_string;
			fastcgi_param REQUEST_METHOD  $request_method;
			fastcgi_param CONTENT_TYPE    $content_type;
			fastcgi_param CONTENT_LENGTH  $content_length;
		}
		
		#location / {
		#	try_files $uri $uri/ /index.php?$query_string;
		#}

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

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

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

Создать файл docker-compose.yaml и заполнить:

version: '3'

networks:
  default:
    external:
      name: network

services:

  php7:
    image: "php:7.4.23-fpm"
    container_name: "prefix-php"
    expose:
      - 9000
    volumes:
      - ./www:/usr/share/nginx

  nginx:
    image: "nginx:1.13.6"
    container_name: "prefix-nginx"
    links:
      - php7
    volumes:
      - ./www:/usr/share/nginx
      - ./conf:/etc/nginx
    labels:
      - traefik.enable=true
      - traefik.http.routers.apache2.rule=Host(`cdn.yourtunes.ru`)
      - traefik.http.services.apache2.loadbalancer.server.port=80

Сборка и запуск:

# docker-compose up