I have the following setup:
version: '2'
services:
web:
build: ./nginx
links:
- "php"
ports:
- "8080:80"
- "443:443"
volumes:
- ./build:/var/www/magento/build/
- ./vagrant/tools:/var/www/tools
php:
image: php:7.2-fpm
volumes:
- ./build:/var/www/magento/build/
- ./vagrant/etc/php/7.1/fpm/conf.d/90-custom.ini:/etc/php-fpm/fpm/conf.d/90-custom.ini
- ./vagrant/etc/php/7.1/cli/conf.d/90-custom.ini:/etc/php-fpm/cli/conf.d/90-custom.ini
- ./vagrant/etc/php/7.1/fpm/pool.d/www_ps.conf:/etc/php-fpm/fpm/pool.d/www_ps.conf
links:
- "cache"
- "mysql"
solr:
build: ./solr
ports:
- "8983:8080"
links:
- "mysql"
volumes:
- solr0-data:/var/solr/core0/data/
varnish:
build: ./varnish
ports:
- "80:80"
links:
- "web"
- "php"
mysql:
image: mariadb:latest
ports:
- "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=xxx
- MYSQL_DATABASE=xxx
volumes:
- mysql:/var/lib/mysql
cache:
build: ./redis
ports:
- "6379:6379"
session:
build: ./redis
ports:
- "6389:6379"
volumes:
solr0-data:
mysql:
In my nginx-config file I use:
# Varnish
upstream varnish_com {
keepalive 100;
server varnish;
}
Usage in the same file:
server {
listen 443 http2;
server_name www.cs.test;
ssl_certificate /etc/ssl/nginx.pem;
ssl_certificate_key /etc/ssl/nginx.key;
ssl_session_cache shared:SSL:20m;
ssl_session_timeout 180m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers MD5:ECDH+AESGCM:ECDH+AES256:ECDH+AES128:DH+3DES:!ADH:!AECDH;
rewrite ^/(nl|fr|es|it|en)/(.*)$ /$2 last;
location / {
...
proxy_pass http://varnish_com;
}
}
Output on console:
web_1 | 2018/07/02 15:39:31 [emerg] 1#1: host not found in upstream "varnish" in /etc/nginx/sites-enabled/com.localhost:5
web_1 | nginx: [emerg] host not found in upstream "varnish" in /etc/nginx/sites-enabled/com.localhost:5
xxx_web_1 exited with code 1
Why isnt nginx able to resolve "varnish" as host? AFAIK Docker autoaliases hostnames in order to avoid the IP-hustle. However it seems that nginx isn't able to fully resolve "varnish" as hostname, thus cannot resolve http://varnish_com to http://[IP OF VARNISH CONTAINER]. :(
update you docker-compose file to use varnish like:
varnish:
hostname: varnish_com
build: ./varnish
basically, I have added hostname. Now your docker container wont get some random name. hopefully, it should fix the issue mentioned.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.