【发布时间】:2023-03-07 06:43:01
【问题描述】:
我有一个带有 php-fpm 和 nginx 的简单 docker-compose 配置,但我看不到任何 php 文件。当我转到 localhost 时,它显示 File Not Found。
我尝试了所有可以在网上找到的方法,但我尝试的所有方法都失败了。 它适用于 html,但不适用于 php 文件。似乎是路径问题,或类似的问题。
我docker-compose logs时遇到这个错误:
project3-php_1 | 172.17.0.5 - 29/Mar/2016:13:29:12 +0000 "GET /index.php" 404
project3-front_1 | 172.17.0.1 - - [29/Mar/2016:13:29:12 +0000] "GET / HTTP/1.1" 404 27 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36"
project3-front_1 | 2016/03/29 13:29:12 [error] 8#8: *3 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.17.0.1, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://172.17.0.2:9000", host: "localhost"
这是我的 docker-compose:
project3-front:
image: nginx
ports:
- "80:80"
links:
- "project3-php:project3-php"
volumes:
- ".:/home/docker"
- "./nginxdir/default.conf:/etc/nginx/conf.d/default.conf"
- "./html:/usr/share/nginx/html"
project3-php:
build: phpdir
volumes:
- ".:/home/docker:rw"
- "./html:/var/www/html"
ports:
- "9000:9000"
working_dir: "/home/docker"
然后是我的 dockerfile for php:
FROM php:5.6-fpm
EXPOSE 9000
我的 nginx 的 default.conf:
server {
listen 80;
server_name localhost;
index index.php index.html;
error_log /var/log/nginx/error.log warn;
access_log /var/log/nginx/access.log;
root /usr/share/nginx/html;
location ~ \.php$ {
fastcgi_pass project3-php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
主文件夹密码为:
/media/revenge/share/PROJECTS/docker_images/php7-nginx
文件层次结构是:
├── docker-compose.yml
├── html
│ ├── index.php
├── nginxdir
│ ├── default.conf
├── phpdir
│ ├── dockerfile
│ └── php.ini
整个文件夹是chmod 777
任何想法将不胜感激。我确定有些东西我没有得到。提前致谢。
【问题讨论】:
标签: php nginx docker http-status-code-404 docker-compose