Why my nginx virtual host inside docker does not work?

by Krystian   Last Updated December 28, 2017 23:00 PM

I'm in the process of moving my services from virtual machines to docker containers. I have moved several of my web apps, confirmed them working and finally decided to move my nginx.

After moving nginx to docker, none of my webapps respond. I have confirmed, that nginx virtual hosts don't work. Only the default configuration, when accessed using IP address works. It looks like it would not get details about the domain used in request.

A sample of my virtual host config:

server {
  listen 80;
  server_name my_domain.eu;
  access_log  /var/log/nginx/my_domain.eu.access.log;
  error_log /var/log/nginx/my_domain.eu.error.log;
  location / {
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Server $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  error_page 500 502 503 504 /default.html;
  location ~* /default\.(jpg|html)$ {
    root /var/www/tomcat/errors;

My docker is configured with a custom network using macvlan driver. All of my containers have a static IP address. I use the default nginx docker image. Here's the relevant part of the docker-compose.yml file:

    container_name: nginx
    image: nginx
      - nginx_config:/etc/nginx/
      - nginx_static:/var/www/
      - "80:80"
    restart: on-failure

As I have said, I have confirmed the nginx working both by checking the logs and by accessing the server using IP address.

I suspect that I have messed something with my docker configuration, since the only changes I have made no changes to the nginx config. I would be grateful for any hints and tips on what could go wrong and where to look at.

When configuring the traffic, I always use the IP address of the container, not the host machine.

Tags : nginx docker

Related Questions

Browser services' container in Docker Swarm mode

Updated April 26, 2017 08:00 AM

How to make AWS containers communicate

Updated January 02, 2018 23:00 PM

Docker Nginx reverse proxy configuration

Updated May 08, 2018 23:00 PM