nginx 和 php 出现 404 未找到

nginx 和 php 出现 404 未找到

我进入了浏览器:

404 Not Found
nginx/1.13.10

并在日志中我得到:

$ ls logs/
nginx-access.log    nginx-error.log
$ cat logs/*
172.17.0.1 - - [27/Mar/2018:02:11:35 +0000] "GET / HTTP/1.1" 404 572 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36" "-"
2018/03/27 02:11:35 [error] 5#5: *1 "/var/wwww/html/index.php" is not found (2: No such file or directory), client: 172.17.0.1, server: localhost, request: "GET / HTTP/1.1", host: "localhost"

我的nginx/nginx.conf样子是这样的:

server {
    listen  80;

    # this path MUST be exactly as docker-compose.fpm.volumes,
    # even if it doesn't exists in this dock.
    root /var/wwww/html;
    index index.php index.html index.html;

    server_name localhost;

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass phpfpm: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-compose.yml样子是:

nginx:
    image: nginx
    restart: always
    ports:
        - "80:80"
    links:
        - phpfpm
        - db
    volumes:
        - ./logs/nginx-error.log:/var/log/nginx/error.log
        - ./logs/nginx-access.log:/var/log/nginx/access.log
        - ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf
        - ./public/:/var/www/html

phpfpm:
    build: ./mGSV
    restart: always
    ports:
        - "9000:9000"
    links:
        - db
    volumes:
        - ./public/:/var/www/html

db:
    image: mariadb
    restart: always
    environment:
          - MYSQL_ROOT_PASSWORD=admin
          - MYSQL_DATABASE=mgsv
          - MYSQL_USER=mgsv_user
          - MYSQL_PASSWORD=mgsvpass
    ports:
          - "3306:3306"
    volumes:
          - ./mysql/:/docker-entrypoint-initdb.d 

phpmyadmin:
  image: phpmyadmin/phpmyadmin
  restart: always
  links:
    - db
  ports:
    - 8183:80
  environment:
    PMA_USER: root
    PMA_PASSWORD: admin
    PMA_ARBITRARY: 1

我的./mGSV/Dockerfile依据是:

FROM php:5-fpm

我错过了什么?

先感谢您。

答案1

我不熟悉docker,但是我发现这里有两个不一致的地方:

独立于 docker 部分,nginx ( nginx/nginx.conf) 尝试从 /var/ 提供内容哇喔/html。这可能是拼写错误(您是这个意思吗/var/www/html?)。因此,确切的错误消息是"/var/wwww/html/index.php" is not found (2: No such file or directory)- 此文件夹中必须有内容,此 nginx 配置才能正常工作。

另外你的 nginx 评论说# this path MUST be exactly as docker-compose.fpm.volumes,但是phpfpm卷的一部分docker-compose.yml./public/:/var/www/html

您究竟想要实现什么?

相关内容