У локального хоста в Docker есть проблема с конфликтующим именем сервера - PullRequest
0 голосов
/ 11 декабря 2018

Я пытаюсь запустить образ докера с localhost.Код с открытым исходным кодом и здесь:

https://github.com/Helium-MVC/Boilerplate

Когда я запускаю docker-compose up, я получаю следующее:

helium_nginx | 2018/12/11 07:43:31 [warn] 1#1: conflicting server name "localhost" on 0.0.0.0:80, ignored
helium_nginx | nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored

Теперь мой докер site.confИмеется только 1 vhost:

server {
    #The port to listen on. SSL would listen on 443
    listen 80 default_server;

    #The name/alias the server listens for when deciding to use this configuration
    server_name  localhost _;

    #Where the lo files are being written too
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;

    #Location of our site
    location / {
            #The root of the site is in public_html
        root    /code/site/public_html/;
        index  index.php index.html index.htm;
        #important for pretty url and routing
        try_files $uri $uri/ /index.php?rt=$uri&$args;
    }                                                                 
}

С установленным в yml следующим образом:

web:
    image: nginx:latest
    container_name: "helium_nginx"
    ports:
      - "8000:80"
    volumes:
      - ./:/code
      - ./site.conf:/etc/nginx/conf.d/site.conf
      - ./nginx_custom_settings.conf:/etc/nginx/conf.d/nginx_custom_settings.conf
    links: ['php']

Что странно, если я заменю server_name на что-то вроде www.example.com и поместите это имя в мой /etc/hosts файл, , он работает !В противном случае, используя localhost, я получаю только страницу nginx по умолчанию .Что может быть не так?

1 Ответ

0 голосов
/ 16 декабря 2018

Чтобы получить ответ, мне пришлось изменить конфигурацию nginx по умолчанию.В своем YML я добавил:

services:
  web:
    image: nginx:latest
    container_name: "helium_nginx"
    ports:
      - "8000:80"
    volumes:
      - ./:/usr/share/nginx/html
      - ./:/code
      - ./site.conf:/etc/nginx/conf.d/site.conf
    additionnx.conf:/etc/nginx/nginx.conf

добавление было - ./nginx.conf:/etc/nginx/nginx.conf

Копируемый файл nginx.conf был следующим:

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/site.conf;
}

То, что я изменил, быловместо того, чтобы включать /etc/nginx/conf.d/*.conf;, который загружал бы всю конфигурацию, я загрузил только ту, которую хотел, включив /etc/nginx/conf.d/site.conf;

...