0

Since a few weeks i'm working with Docker/Docker-Compose and Linux.

I'm wondering if it's possible to tune my nginx Performance. All the info I found online where for standard Nginx on Linux and not in a Docker Container.

Here you can see my Docker-Compose and my Nginx default conf.

Maybe you can give me a hint on what I can do better.

Thanks

Docker-Compose----------------------------------------

version: '3.7'

services:
  traefik:
    image: traefik:v2.4
    container_name: traefik
    restart: always
    security_opt:
      - no-new-privileges:true
    ports:
      - 80:80
      - 443:443
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - ./apps/traefik/traefik.yml:/traefik.yml:ro
      - ./apps/traefik/acme.json:/acme.json
      - ./apps/traefik/configurations:/configurations
    networks:
      - proxy
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.traefik.entrypoints=websecure"
      - "traefik.http.routers.traefik.rule=Host(`traefik.domain.com`)"
      - "traefik.http.routers.traefik.service=api@internal"
      - "traefik.http.routers.traefik.middlewares=user-auth@file"

nginx:
    image: nginx:latest
    container_name: nginx
    restart: always
    volumes:
      - ./www:/www
      - ./apps/nginx/default.conf:/etc/nginx/conf.d/default.conf
    networks:
      - proxy
      - internal
    links:
      - php-fpm
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=proxy"
      - "traefik.http.routers.nginx.entrypoints=websecure"
      - "traefik.http.routers.nginx.rule=Host(`domain.com`) || Host(`www.domain.com`)"

  php-fpm:
    image: bitnami/php-fpm:latest
    volumes:
      - ./www:/www
    expose:
      - 9000
    networks:
      - internal

 mariadb:
    image: mariadb:latest
    container_name: mariadb
    volumes:
      - ./apps/mariaDB/db-data:/var/lib/mysql
    networks:
      db-net:
      internal:
      host-network:
        ipv4_address: 172.22.0.100
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: 123
      MYSQL_DATABASE: db
      MYSQL_USER: db-user
      MYSQL_PASSWORD: 123

networks:
  proxy:
    driver: host
    external: true
  db-net:
    internal: true
  internal:
    internal: true
  host-network:
    ipam:
      driver: default
      config:
        - subnet: 172.22.0.0/16

Nginx-Conf-----------------------------------------

    Server {    
     server_tokens off;

     listen 80;
     server_name www.domain.com;

     error_log  /www/log/error.log;
     access_log /www/log/access.log;

     root /www;

     location / {
         index index.php index.html;
     }

     location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
        access_log        off;
        log_not_found     off;
        expires           360d;
     }


     location ~* \.php$ {
        fastcgi_pass php-fpm: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 ~ /\. {
        access_log off;
        log_not_found off;
        deny all;
     }
    }
benehil
  • 1
  • 2

1 Answers1

0

According to the answer provided in this post you can increase the performance of the nginx container by running it in the Docker bridge network. Additionally there is another answer that says that running the container in the Docker bridge network it gives better performance as it uses the host's native networking.

drauedo
  • 641
  • 4
  • 17
  • Thanks for the answer, so i only can put on network in driver mode Host. Because of that i set the external proxy network into drover host. Is that correct? Now the performance is the same as in the beginning. – benehil Aug 26 '21 at 11:09
  • I'm sorry, not sure I understand your question. Could you provide more context please? Did my suggestion helped you? – drauedo Aug 26 '21 at 15:37
  • Sry for the late answer. As the other Thread suggested I set the Network driver into Host mode. But I can only set one Network into Host. Is is correct to set the Proxy into Host because he provides the Services? – benehil Aug 29 '21 at 16:10