Nginx-Traefik Reverse Proxy versus NGINX FastCGI Support

I am using docker-compose.yaml to define the services I need for my local development. Recently, I have added a new Traefik service to benefit from Domain Name Service Resolution capabilities that Traefik offers.

A typical Traefik service definition:

version: '3'

services:

  traefik:
    image: "traefik:v2.6.0"
    container_name: coolstuff_solutions_traefik
    command:
      - "--log.level=DEBUG"
      - "--providers.docker"
      - "--api.dashboard=true"
      - "--entrypoints.web.address=:80"
      - "--accesslog.filepath=/data/access.log"
      - "--providers.docker.exposedbydefault=false"
      - "--providers.docker.network=coolstuff-solutions"
    ports:
      - "80:80"
      - "8080:80"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
    labels:
      - "traefik.enable=true"
      - "traefik.default.protocol=http"
      - "traefik.http.routers.frontend.entrypoints=web"
      - "traefik.http.routers.frontend.rule=Host(`coolstuff.localhost`)"
    networks:
      coolstuff-solutions:
        aliases:
          - traefikversion: '3'

services:

  traefik:
    image: "traefik:v2.6.0"
    container_name: coolstuff_solutions_traefik
    command:
      - "--log.level=DEBUG"
      - "--providers.docker"
      - "--api.dashboard=true"
      - "--entrypoints.web.address=:80"
      - "--accesslog.filepath=/data/access.log"
      - "--providers.docker.exposedbydefault=false"
      - "--providers.docker.network=coolstuff-solutions"
    ports:
      - "80:80"
      - "8080:80"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
    labels:
      - "traefik.enable=true"
      - "traefik.default.protocol=http"
      - "traefik.http.routers.frontend.entrypoints=web"
      - "traefik.http.routers.frontend.rule=Host(`coolstuff.localhost`)"
    networks:
      coolstuff-solutions:
        aliases:
          - traefik 

Let us say, that I already had an NGINX service running to support my development attempts through a specified port; maybe designated through the docker-compose.yaml configuration file. In my case I already had an NGINX dedicated service:

nginx:
    image: nginx:alpine
    container_name: coolstuff_solutions_nginx
    volumes:
      - ./app:/var/www
      - ./sys/nginx:/etc/nginx/conf.d/
    labels:
      - "traefik.enable=true"
    networks:
      coolstuff-solutions:
        aliases:
          - nginx

It should be noted that the default.conf file, for NGINX, refers to the php-fpm service with fastcgi_pass app:9000;.

In its own right, NGINX is a Reverse Proxy capable by nature. However, I want to take advantage of the Traefik capabilities.

Is it possible for me to mix Traefix, NGINX, and PHP-FPM if I still want to make use of FastCGI?

Below is the docker-compose.yaml entry for the app container and its related Dockerfile and NGINX config.

#app service exposing API and any other pre-defined accessible endpoints
 app:
    build:
      context: .
      dockerfile: sys/php/Dockerfile
    image: coolstuff_solutions:app
    container_name: coolstuff_solutions_app
    env_file:
      - app/.env
    environment:
      APP_NAME: "CoolStuff Solutions"
    working_dir: /var/www
    depends_on:
      - nginx
    volumes:
      - ./app:/var/www
      - ./app/var/:/var/www/var:rw
      - ./sys/php/default.ini:/usr/local/etc/php/conf.d/local.ini
    labels:
      - "traefik.enable=true"
      - "traefik.default.protocol=http"
      - "traefik.http.routers.app.entrypoints=web"
      - "traefik.http.routers.app.rule=Host(`app.coolstuff.localhost`)"
      - "traefik.http.services.app.loadbalancer.server.port=8080"
      - "traefik.backend=app"
    networks:
      coolstuff-solutions:
        aliases:
          - app

#NGINX for PHP-FPM service
server {
    listen 80;
    index index.php index.html;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /var/www/public;
    location ~ .php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+.php)(/.+)$;
        fastcgi_pass app:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
    location / {
        try_files $uri $uri/ /index.php?$query_string;
        gzip_static on;
    }
}

# PHP-FPM Dockerfile

FROM php:8.2-fpm

ENV USER=www
ENV GROUP=www

# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends 
    git 
    curl 
    libldap2-dev 
    libpng-dev 
    libonig-dev 
    libxml2-dev 
    libgd-dev 
    zip 
    zlib1g-dev 
    librabbitmq-dev 
    unzip 
    ghostscript 
    fontconfig 
    graphviz

RUN pecl install amqp && docker-php-ext-enable amqp

# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Set timezone
RUN rm /etc/localtime 
    && ln -s /usr/share/zoneinfo/Africa/Harare /etc/localtime 
    && "date"

# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd intl

# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer

# Setup working directory
WORKDIR /var/www/

# Create User and Group
RUN groupadd -g 1000 ${GROUP} && useradd -u 1000 -ms /bin/bash -g ${GROUP} ${USER}

# Grant Permissions
RUN chown -R ${USER} /var/www

# Select User
USER ${USER}

# Copy permission to selected user
COPY --chown=${USER}:${GROUP} . .

EXPOSE 9000

CMD ["php-fpm"]

In my view, there should be means to bind Traefik to NGINX such that we can benefit from FastCGI but the fact that we speaking to two Proxy Server products, it seems like something is not adding up.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật