【问题标题】:Docker-Compose with Nginx and PHP -> Nginx Config for PerformanceDocker-Compose with Nginx and PHP -> Nginx Config for Performance
【发布时间】:2021-10-26 07:42:53
【问题描述】:

几周以来,我一直在使用 Docker/Docker-Compose 和 Linux。

我想知道是否可以调整我的 nginx 性能。 我在网上找到的所有信息都适用于 Linux 上的标准 Nginx,而不是 Docker 容器。

在这里你可以看到我的 Docker-Compose 和我的 Nginx 默认配置。

也许你可以给我一个提示,让我知道我可以做得更好。

谢谢

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;
     }
    }

【问题讨论】:

    标签: php docker performance nginx docker-compose


    【解决方案1】:

    根据本文中提供的answer,您可以通过在 Docker 桥接网络中运行 nginx 容器来提高其性能。 此外,还有另一个答案说,在 Docker 桥接网络中运行容器可以提供更好的性能,因为它使用主机的本机网络。

    【讨论】:

    • 感谢您的回答,所以我只能在驱动模式主机下上网。因此,我将外部代理网络设置为驱动程序主机。那是对的吗?现在的表现和开始时一样。
    • 很抱歉,我不确定我是否理解您的问题。你能提供更多的上下文吗?我的建议对你有帮助吗?
    • 对不起,迟到的答案。正如其他线程建议的那样,我将网络驱动程序设置为主机模式。但我只能将一个网络设置为主机。将代理设置为主机是否正确,因为他提供了服务?
    猜你喜欢
    • 2022-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-26
    • 1970-01-01
    • 2018-11-15
    • 2020-12-15
    • 2020-07-22
    相关资源
    最近更新 更多