当我尝试运行docker-compose up时出现此错误:
错误:在/etc/nginx/conf.d/default.conf
的上游“ php-fpm”中找不到主机
下面是我在docker-compose.yml中使用的代码。
docker-composer版本:“ 3.7”
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;
}
}
我在docker文件中为Nginx使用的代码:
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
我有错误,不知道文件default.php中的php-fpm,而且我在docker-compose中添加了选项链接,但也出错了