为什么 nginx.conf 返回“GET /index.php” 404”?
我正在尝试在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论