繁体   English   中英

docker中的nginx和php-fpm:无法finx index.php

[英]nginx & php-fpm in docker: can't finx index.php

试图让nginx通过带有docker compose的fastcgi使用php-fpm php-fpm容器git将容器内的代码拉入/ var / www / code /。 当我从nginx's site.conf文件中注释掉"root /var/www/code"指令时,它正在查看/etc/nginx/html/index.php

web_1         | 2018/04/06 14:59:04 [error] 7#7: *1 "/etc/nginx/html/index.php" is not found (2: No such file or directory), client: 172.19.0.1, server: localhost, request: "GET / HTTP/1.1", host: "0.0.0.0:8080"
web_1         | 172.19.0.1 - - [06/Apr/2018:14:59:04 +0000] "GET / HTTP/1.1" 404 169 "-" "curl/7.47.0"

这是预期的行为吗? 我是否需要将应用程序的代码也包含在var/www/codenginx容器中? 是不是只能为此目的使用php-fpm容器,而不nginx应用程序的代码也存储在nginx容器中?

nginx的site.conf:

server {
    listen 8000;
    index index.php index.html;
    server_name localhost;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /var/www/code;

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

从主持人:

# curl 0.0.0.0:8080
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.13.9</center>
</body>
</html>

从docker日志web_1中:

web_1         | 2018/04/06 14:54:37 [error] 7#7: *5 "/var/www/code/public/index.php" is not found (2: No such file or directory), client: 172.19.0.1, server: localhost, request: "GET / HTTP/1.1", host: "0.0.0.0:8080"
web_1         | 172.19.0.1 - - [06/Apr/2018:14:54:37 +0000] "GET / HTTP/1.1" 404 169 "-" "curl/7.47.0"

docker-comnpose.yaml:

version: '2'

services:
    web:
        build:
          context: ./web
        ports:
            - "8080:8000"
        volumes:
            - ./web/site.conf:/etc/nginx/conf.d/site.conf
        networks:
            - redis-cluster
    php-worker:
      build:
        context: ./php-worker
      ports:
            - 9000:9000
      volumes:
            - ./php-worker/www.conf:/usr/local/etc/php-fpm.d/www.conf
      networks:
        redis-cluster:
#          ipv4_address: 172.18.0.10
    db:
      build:
        context: ./db
networks:
    redis-cluster:
      ipam:
        driver: host
        config:
          - subnet: 172.18.0.0/24

md在您的nginx容器中创建/ var / www / code文件夹? 但我认为将其全部代理到php是一个坏主意。 最好对所有静态属性使用nginx,对php-fpm使用动态属性

这是在我的情况下有效的nginx配置:

server {
    listen       8000 default_server;
    server_name  localhost;
    root   /var/www/code;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

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

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }


    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        fastcgi_pass   php-worker:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM