I recieving error nginx:
[emerg] host not found in upstream "varnish" in /etc/nginx/conf.d/default.conf:53
error in varnish log
Backend host '"web"' could not be resolved to an IP address: Temporary failure in name resolution (Sorry if that error message is gibberish.) ('/etc/varnish/default.vcl' Line 9 Pos 13) .host = "web";
it seems to have a dependency loop, making docker unable to start both varnish and nginx.
Anyone have any idea about this?
File docker-compose.yml
web:
image: magento/magento-cloud-docker-nginx:latest
ports:
- 80:80
- 443:443
- 8080:8080
links:
- fpm
- fpm_xdebug
- db
volumes_from:
- appdata
volumes:
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
- ./nginx/ssl:/etc/nginx/ssl
env_file:
- ./global.env
varnish:
build: ./varnish
depends_on:
- web
links:
- web
ports:
- 6082:6082
- 6081:6081
volumes:
- ./varnish/etc/varnish/default.vcl:/etc/varnish/default.vcl
- ./varnish/etc/default/varnish:/etc/default/varnish
My config default.conf
upstream fastcgi_backend {
# use tcp connection
server fpm:9000;
}
server {
listen 80;
server_name local.defaultsite.com;
return 301 https://$server_name$request_uri;
}
server {
listen 8080;
server_name local.defaultsite.com;
# set $MAGE_ROOT /app;
set $MAGE_ROOT /home/webapps/public_html;
# include /app/nginx.conf.sample;
include /home/webapps/public_html/nginx.conf.sample;
}
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
ssl_certificate /etc/nginx/ssl/cert.pem;
ssl_certificate_key /etc/nginx/ssl/key.pem;
set $MAGE_ROOT /home/webapps/public_html;
set $MAGE_DEBUG_SHOW_ARGS 0;
set $my_fastcgi_pass "fastcgi_backend";
if ($cookie_XDEBUG_SESSION) {
set $my_fastcgi_pass "fastcgi_backend_xdebug";
}
server_name local.defaultsite.com;
location / {
proxy_pass http://varnish:6081;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For
$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Port 443;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
fastcgi_buffer_size 32k;
fastcgi_buffers 4 32k;
}
}
In varnish default.vcl
backend default {
.host = "web";
.port = "8080";
.first_byte_timeout = 600s;
}
CodePudding user response:
The problem starts with the fact that your Nginx configuration uses the following upstream configuration for FastCGI:
upstream fastcgi_backend {
# use tcp connection
server fpm:9000;
}
The hostname is fpm
which probably refers to a PHP-FPM Docker container. This container doesn't seem to be part of your docker-compose.yml
setup.
Chances are that your web
container doesn't recover from this and goes down (please see docker-compose
output logs).
Varnish depends on the web
hostname to proxy its data, but since it no longer resolves, Varnish also throws an error.
Have a look at https://hub.docker.com/_/php?tab=tags&page=1&name=fpm: it lists all available FPM-based images for the official PHP image. You could go for php:7.4-fpm
.