为什么 nginx.conf 返回“GET /index.php” 404”?

发布于 2025-01-11 11:24:19 字数 2095 浏览 0 评论 0原文

我正在尝试在 Docker 中配置 nginx 配置,但是当我启动“sudo docker-compose up -d”并尝试连接到“http://localhost:8098/”时,我看到:找不到文件。 和日志如下:

docker-infrastructure_php-fpm_1 | 172.19.0.3 -  03/Mar/2022:21:35:35 +0000 "GET /index.php" 404
docker-infrastructure_nginx_1 | 172.19.0.1 - - [03/Mar/2022:21:35:35 +0000] "GET / HTTP/1.1" 404 27 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36" "-"`

有我的: nginx.conf

server {
    listen 80;
    server_name dgtips-backend-local;
    root /home/sergey/PhpstormProjects/dgtips-backend/public;
    index index.php;

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

    location ~ [^/]\.php(/|$) {

        fastcgi_param SCRIPT_FILENAME /home/sergey/PhpstormProjects/dgtips-backend$fastcgi_script_name;
        fastcgi_pass php-fpm:9000;
        fastcgi_index index.php;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
    }
}

nginx.Dockerfile

FROM nginx

ADD docker/nginx/nginx.conf /etc/nginx/conf.d/default.conf

WORKDIR /home/sergey/PhpstormProjects/dgtips-backend/public

docker-compose.yml

version: "3.3"

services:
    nginx:
        build:
          context: .
          dockerfile: docker/nginx/nginx.Dockerfile
        ports:
            - 8098:80
        volumes:
          - ./:/home/sergey/PhpstormProjects/dgtips-backend
        links:
          - php-fpm
    php-fpm:
        build:
            context: .
            dockerfile: docker/php-fpm/fpm.Dockerfile
        volumes:
          - ./:/home/sergey/PhpstormProjects/dgtips-backend

最后 fpm.Dockerfile

FROM php:7.4-fpm

RUN apt-get update \
&& docker-php-ext-install pdo pdo_mysql

我完全确定我的(本地)项目和 index.php 文件的路径正确

I'm trying to configure nginx config in Docker but when I start "sudo docker-compose up -d" and try to connect to "http://localhost:8098/" I see: File not found. and logs like:

docker-infrastructure_php-fpm_1 | 172.19.0.3 -  03/Mar/2022:21:35:35 +0000 "GET /index.php" 404
docker-infrastructure_nginx_1 | 172.19.0.1 - - [03/Mar/2022:21:35:35 +0000] "GET / HTTP/1.1" 404 27 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36" "-"`

There are my:
nginx.conf

server {
    listen 80;
    server_name dgtips-backend-local;
    root /home/sergey/PhpstormProjects/dgtips-backend/public;
    index index.php;

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

    location ~ [^/]\.php(/|$) {

        fastcgi_param SCRIPT_FILENAME /home/sergey/PhpstormProjects/dgtips-backend$fastcgi_script_name;
        fastcgi_pass php-fpm:9000;
        fastcgi_index index.php;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
    }
}

nginx.Dockerfile

FROM nginx

ADD docker/nginx/nginx.conf /etc/nginx/conf.d/default.conf

WORKDIR /home/sergey/PhpstormProjects/dgtips-backend/public

docker-compose.yml

version: "3.3"

services:
    nginx:
        build:
          context: .
          dockerfile: docker/nginx/nginx.Dockerfile
        ports:
            - 8098:80
        volumes:
          - ./:/home/sergey/PhpstormProjects/dgtips-backend
        links:
          - php-fpm
    php-fpm:
        build:
            context: .
            dockerfile: docker/php-fpm/fpm.Dockerfile
        volumes:
          - ./:/home/sergey/PhpstormProjects/dgtips-backend

And finally
fpm.Dockerfile

FROM php:7.4-fpm

RUN apt-get update \
&& docker-php-ext-install pdo pdo_mysql

I'm completely sure that I have correct paths to my (local) project and to my index.php file

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文