如何调试Docker容器请求流

时间:2019-05-03 14:00:34

标签: php laravel docker docker-compose

当前我有2个docker容器,一个用于nginx,另一个用于php-fpm。 这是我的docker-compose.yml:

version: "3"

services:
    web:
        image: nginx:latest
        ports:
            - "8880:80"
        volumes:
            - .:/usr/share/nginx/html/hr_laravel
            - ./site.conf:/etc/nginx/conf.d/site.conf
            - ./storage/logs/nginx/access.log:/var/log/nginx/access.log
            - ./storage/logs/nginx/error.log:/var/log/nginx/error.log
        links:
            - php

    php:
        image: php:7-fpm
        ports:
            - "9090:9000"
        volumes:
        - .:/var/www/html/hr_laravel

这是site.conf:

server {
    listen   80;
    server_name hr.local;

    root /usr/share/nginx/html/hr_laravel/public;
    index index.php index.html;

    error_log  /var/log/nginx/error.log debug;
    access_log /var/log/nginx/access.log;

    location / {
        try_files $uri $uri/ @hr_laravel;
    }

    location @hr_laravel {
        rewrite /hr_laravel/(.*)$ /hr_laravel/index.php?/$1 last;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

如果我运行docker并打开网站,它将显示File Not Found,并在日志中显示

2019/05/03 13:51:25 [error] 7#7: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.22.0.1, server: hr.local, request: "GET / HTTP/1.1", upstream: "fastcgi://172.22.0.2:9000", host: "hr.local:8880"

我需要找出如何调试Web请求流程的方法,从nginx容器开始,然后将其传递到php-fpm容器中,这样我就知道会发生什么。

0 个答案:

没有答案