Docker NGINX将无法服务于两个站点

时间:2019-02-28 06:08:12

标签: docker nginx

我第一次使用Docker,试图构建NGINX代理(也是第一次使用NGINX)。我看过多个指南,似乎都暗示我走了正确的路,但是运行图像时,我得到了duplicate listen options for [::]:80 in /etc/nginx/conf.d/site.conf

site.conf:

server {
    listen 80;
    listen [::]:80 ipv6only=on;

    server_name gamersplane.local;
    root /var/www;
    index dispatch.php;

    location / {
         try_files $uri /dispatch.php$is_args$args;
    }

    location ~ \.php$ {
        try_files $uri /dispatch.php =404;
        fastcgi_pass api:9000;
        fastcgi_index dispatch.php;
        fastcgi_buffers 16 16k;
        fastcgi_buffer_size 32k;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        #fixes timeouts
        fastcgi_read_timeout 600;
        include fastcgi_params;
    }
}

api.conf:

server {
    listen 80;
    listen [::]:80 ipv6only=on;

    server_name api.gamersplane.local;
    root /var/www/api;
    index dispatch.php;

    location / {
         try_files $uri /dispatch.php$is_args$args;
    }

    location ~ \.php$ {
        try_files $uri /dispatch.php =404;
        fastcgi_pass api:9000;
        fastcgi_index dispatch.php;
        fastcgi_buffers 16 16k;
        fastcgi_buffer_size 32k;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        #fixes timeouts
        fastcgi_read_timeout 600;
        include fastcgi_params;
    }
}

我有两个撰写文件:

docker-compose.yal

  proxy:
    build:
      context: ./nginx
      dockerfile: Dockerfile
    container_name: gamersplane-proxy
    ports:
      - 80:80
    volumes:
      - ../:/var/www

docker-compose.dev.yml

  proxy:
    volumes:
      - ./nginx/dev/site.conf:/etc/nginx/conf.d/site.conf
      - ./nginx/dev/api.conf:/etc/nginx/conf.d/api.conf

1 个答案:

答案 0 :(得分:0)

您需要根据documentation删除ipv6_only=on

  

此参数默认情况下处于打开状态。只能在启动时设置一次。

因此无需将其添加到您的配置中