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.

  • did you try reaching it by name from a workstation that is not a docker host? i've had similar issues when using 'localhost' to hit docker containers. – mdeanda Dec 29 '17 at 0:27
  • But I never use localhost :/ And I can reach it via ip without issues. – Krystian Dec 29 '17 at 8:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.