簡體   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