nginx的PHP-fpm速度很慢,

时间:2019-02-26 17:33:18

标签: php docker nginx

因此,我一直在Docker容器(nginx连接到php-fpm)上运行一些基准测试,它比裸机慢70倍以上。与每秒7,000的裸机相比,我每秒可以处理100个请求。

docker-compose.yml:

version: '3'

services:
    #web
    frontend:
        build:
            context: ./environment/nginx
            dockerfile: ./Dockerfile
        container_name: nginx_software
        restart: always
        ports:
            - 80:80
        volumes:
            - ./environment/nginx/nginx.conf:/etc/nginx/nginx.conf
        links:
            - php
    php:
        build:
            context: ./environment/php
            args:
                version: 7.3-fpm
            dockerfile: ./Dockerfile
        container_name: php_software
        restart: always
        ports:
            - 9000:9000
        volumes:
            - ./api:/var/www/software:cached
        links:
            - mysql
    mysql:
        build:
            context: ./environment/mysql
            args:
                version: 5.7
            dockerfile: ./Dockerfile
        container_name: mysql_software
        command: --default-authentication-plugin=mysql_native_password
        restart: always
        ports:
            - 3306:3306
        volumes:
            - ./environment/mysql/data:/var/lib/mysql
        environment:
            MYSQL_ROOT_PASSWORD: software
            MYSQL_DATABASE: software
            MYSQL_USER: software
            MYSQL_PASSWORD: software

我的nginx.conf

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {

}

http {

    include /etc/nginx/mime.types;

    server {

        listen 80;
        listen [::]:80;
        server_name software.test;
        root /usr/share/nginx/html/software;

        add_header X-Frame-Options "SAMEORIGIN";
        add_header X-XSS-Protection "1; mode=block";
        #add_header X-Content-Type-Options "nosniff";

        index index.html;

        location / {
            try_files $uri $uri/ =404;
        }

        charset utf-8;
    }

    server {
        listen 80;
        listen [::]:80;
        server_name api.software.test;
        root /var/www/software/public;

        add_header X-Frame-Options "SAMEORIGIN";
        add_header X-XSS-Protection "1; mode=block";
        #add_header X-Content-Type-Options "nosniff";

        index index.php;

        charset utf-8;

        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }

        error_page 404 /index.php;

        location ~ \.php$ {

            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO       $fastcgi_path_info;
            fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;

            fastcgi_pass   php:9000;
            fastcgi_index index.php;
        }

        location ~ /\.(?!well-known).* {
            deny all;
        }
    }

}

我用于nginx的dockerfile,只需将conf文件复制到/ etc / nginx文件夹中。

如果我构建一个自定义的fpm文件,或使用以下文件:https://github.com/uvd/php-docker-bench我获得了正确的RPS数量(7,000),但是使用我当前的nginx / fpm设置,我几乎没有超过100 RPS。我在做什么错,有什么想法吗?

0 个答案:

没有答案