简体   繁体   English

Docker 上的本地主机有“冲突的服务器名称”问题

[英]Localhost on Docker Has "conflicting server name" Problem

I am trying to launch a docker image with localhost.我正在尝试使用本地主机启动 docker 映像。 The code is open sourced and here:代码是开源的,在这里:

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

When I run docker-compose up , I get the following:当我运行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

Now my docker site.conf only has 1 vhost:现在我的 docker site.conf 只有 1 个虚拟主机:

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;
    }                                                                 
}

With it set in the yml like so:像这样在 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']

What is weird is that is if I change the server_name to something like www.example.com and place that name in my /etc/hosts file, it works !奇怪的是,如果我将server_name更改为 www.example.com 之类的名称并将该名称放在我的/etc/hosts文件中,它就可以工作 Otherwise using localhost I get only the nginx default page .否则使用 localhost 我只能得到nginx 默认页面 What can be wrong?有什么问题?

To provide an answer, I had to change the default nginx configuration.为了提供答案,我不得不更改默认的 nginx 配置。 In my YML I added:在我的 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

The addittion was the -./nginx.conf:/etc/nginx/nginx.conf添加的是-./nginx.conf:/etc/nginx/nginx.conf

The nginx.conf being copied was this:被复制的 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;
}

What I changed was instead of having include /etc/nginx/conf.d/*.conf;我改变的是 include /etc/nginx/conf.d/*.conf; that would load all configuration, I loaded just the one I wanted, include /etc/nginx/conf.d/site.conf;这将加载所有配置,我只加载了我想要的配置,包括/etc/nginx/conf.d/site.conf;

I'm using the nginx image in docker, which has a default.conf file with server_name localhost and listening port 80. I simply replace that file and get this resolved.我在 docker 中使用nginx图像,它有一个带有server_name localhost和侦听端口 80 的default.conf文件。我只需替换该文件并解决这个问题。

docker-compose.yml docker-compose.yml

version: '2'
services:
  nginx: 
    image: nginx:latest
    volumes:
      - ./tmp/https_reverse_proxy.conf:/etc/nginx/conf.d/https_reverse_proxy.conf
      - ./tmp/http_reverse_proxy.conf:/etc/nginx/conf.d/default.conf
    ports:
      - 80:80
      - 443:443

and http_reverse_proxy.conf和 http_reverse_proxy.conf

server {
  listen 80;

  server_name localhost;

  return 301 https://$host$request_uri;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 nginx 冲突的服务器名称,但不同的端口 - nginx conflicting server name, but different ports PHP问题(在localhost上有效,但在Web服务器上错误) - Problem with PHP (works on localhost, but errors on web server) 为什么我收到错误“'在 localhost 启动 PHP 内置服务器'遇到问题。只有 CLI SAPI 提供内置 Web 服务器”? - Why am I getting the error "'Starting PHP Built-in Server at localhost' has encountered a problem. Only the CLI SAPI provides a built-in web server"? 在 docker 容器中启动 Laravel 服务器的小问题 - A little problem with starting Laravel server in docker container 无法将 NGINX docker 容器连接到本地主机 php 服务器 - Unable to connect NGINX docker container to localhost php server 在服务器中通过gmail smtp发送邮件时出现问题,但在localhost中工作正常 - problem in sending mail by gmail smtp in server but works fine in localhost 将我的Codeigniter站点从实时服务器移动到本地主机时出现问题 - Problem in moving my Codeigniter site from live server to localhost 缓存问题? 服务器端事件在本地主机中工作,而不是在生产环境中 - Cache problem? Server side events work in localhost, not in production enviroment $ Request变量在实时服务器上变为null,但在production(localhost)中有一个值 - $Request variable becomes null on live server but it has a value in production(localhost) 使用 docker-compose 构建 PHP 时 sudo 有问题 - Building PHP with docker-compose up has problem with sudo
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM