在“上游”中找不到主机;php fpm“;在/etc/nginx/conf.d/default.conf中
我在尝试运行docker compose时遇到以下错误: 错误:在/etc/nginx/conf.d/default.conf中的上游“php fpm”中找不到主机 下面是我在docker-compose.yml中使用的代码 docker composer版本:“3.7”在“上游”中找不到主机;php fpm“;在/etc/nginx/conf.d/default.conf中,php,docker,nginx,Php,Docker,Nginx,我在尝试运行docker compose时遇到以下错误: 错误:在/etc/nginx/conf.d/default.conf中的上游“php fpm”中找不到主机 下面是我在docker-compose.yml中使用的代码 docker composer版本:“3.7” services: ngnix: build: args: VERSION: $NGINX_VERSION context: . dockerfile: ./do
services:
ngnix:
build:
args:
VERSION: $NGINX_VERSION
context: .
dockerfile: ./docker/nginx/Dockerfile
target: dev
volumes:
- .:/app
depends_on:
- php-fpm
links:
- php-fpm
ports:
- 81:80
networks:
- inluccnetwork
php-fpm:
build:
args:
VERSION: $PHP_VERSION
context: .
dockerfile: ./docker/php-fpm/Dockerfile
target: dev
volumes:
- .:/app
networks :
- inluccnetwork
command: sh -c 'composer install --no-interaction --optimize-autoloader && php-fpm'
networks:
inluccnetwork :
driver: bridge
位于/etc/Nginx/conf.d/default.conf的Nginx配置文件代码:
server {
listen 80;
root /app/web;
include mime.types;
index app_dev.php index.html index.htm;
location / {
try_files $uri @rewriteapp;
}
location @rewriteapp {
rewrite ^(.*)$ /app_dev.php/$1 last;
}
# DEV
# This rule should only be placed on your development environment
# In production, don't include this and don't deploy app_dev.php or config.php
location ~ ^/(app_dev|config)\.php(/|$) {
fastcgi_pass php-fpm:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $document_root;
internal;
}
# PROD
location ~ ^/app\.php(/|$) {
fastcgi_pass php-fpm:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $document_root;
internal;
}
# return 404 for all other php files not matching the front controller
# this prevents access to other php files you don't want to be accessible.
location ~ \.php$ {
return 404;
}
location /test {
return 200 '<h1>ok</h1>';
}
error_log syslog;
access_log syslog;
location ~ /\.ht {
deny all;
}
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|mp4|ogg|ogv|webm|htc)$ {
access_log off;
root /app/web;
add_header Cache-Control "max-age=2592000";
expires max;
log_not_found off;
}
# CSS and Javascript
location ~* \.(?:css|js)$ {
add_header Cache-Control "max-age=31536000";
access_log off;
expires max;
log_not_found off;
}
}
我在default.php文件中不知道php fpm有错误,并且我在docker compose中添加了选项链接,但也有错误您要传递到php fpm:9000您可能要传递到127.0.0.1:9000
ARG VERSION
# Dev image
FROM nginx:1.15-alpine as dev
# Copy nginx config
COPY ./docker/nginx/default.conf /etc/nginx/conf.d/default.conf
# Prod image
FROM dev as prod
# Copy assets
COPY ./assets /app/web